18 #include <itkFastChamferDistanceImageFilter.h> 19 #include <itkInvertIntensityImageFilter.h> 20 #include <itkIsoContourDistanceImageFilter.h> 21 #include <itkSubtractImageFilter.h> 25 unsigned int lowerSliceIndex,
27 unsigned int upperSliceIndex,
28 unsigned int requestedIndex,
41 float ratio = (float)(requestedIndex - lowerSliceIndex) / (float)(upperSliceIndex - lowerSliceIndex);
43 resultImage, InterpolateIntermediateSlice, 2, upperDistanceImage, lowerDistanceImage, ratio);
48 template <
typename TPixel,
unsigned int VImageDimension>
49 void mitk::ShapeBasedInterpolationAlgorithm::ComputeDistanceMap(
const itk::Image<TPixel, VImageDimension> *binaryImage,
52 typedef itk::Image<TPixel, VImageDimension> DistanceFilterInputImageType;
54 typedef itk::FastChamferDistanceImageFilter<DistanceFilterImageType, DistanceFilterImageType> DistanceFilterType;
55 typedef itk::IsoContourDistanceImageFilter<DistanceFilterInputImageType, DistanceFilterImageType> IsoContourType;
56 typedef itk::InvertIntensityImageFilter<DistanceFilterInputImageType> InvertIntensityImageFilterType;
57 typedef itk::SubtractImageFilter<DistanceFilterImageType, DistanceFilterImageType> SubtractImageFilterType;
59 typename DistanceFilterType::Pointer distanceFilter = DistanceFilterType::New();
60 typename DistanceFilterType::Pointer distanceFilterInverted = DistanceFilterType::New();
61 typename IsoContourType::Pointer isoContourFilter = IsoContourType::New();
62 typename IsoContourType::Pointer isoContourFilterInverted = IsoContourType::New();
63 typename InvertIntensityImageFilterType::Pointer invertFilter = InvertIntensityImageFilterType::New();
64 typename SubtractImageFilterType::Pointer subtractImageFilter = SubtractImageFilterType::New();
67 int maximumDistance = 100;
70 invertFilter->SetInput(binaryImage);
71 invertFilter->SetMaximum(1);
74 isoContourFilter->SetInput(binaryImage);
75 isoContourFilter->SetFarValue(maximumDistance + 1);
76 isoContourFilter->SetLevelSetValue(0);
78 isoContourFilterInverted->SetInput(invertFilter->GetOutput());
79 isoContourFilterInverted->SetFarValue(maximumDistance + 1);
80 isoContourFilterInverted->SetLevelSetValue(0);
82 distanceFilter->SetInput(isoContourFilter->GetOutput());
83 distanceFilter->SetMaximumDistance(maximumDistance);
85 distanceFilterInverted->SetInput(isoContourFilterInverted->GetOutput());
86 distanceFilterInverted->SetMaximumDistance(maximumDistance);
89 subtractImageFilter->SetInput2(distanceFilter->GetOutput());
90 subtractImageFilter->SetInput1(distanceFilterInverted->GetOutput());
91 subtractImageFilter->Update();
96 template <
typename TPixel,
unsigned int VImageDimension>
97 void mitk::ShapeBasedInterpolationAlgorithm::InterpolateIntermediateSlice(itk::Image<TPixel, VImageDimension> *result,
102 typename DistanceFilterImageType::Pointer lowerITK = DistanceFilterImageType::New();
103 typename DistanceFilterImageType::Pointer upperITK = DistanceFilterImageType::New();
108 itk::ImageRegionConstIteratorWithIndex<DistanceFilterImageType> lowerIter(lowerITK,
109 lowerITK->GetLargestPossibleRegion());
111 lowerIter.GoToBegin();
113 if (!lowerITK->GetLargestPossibleRegion().IsInside(upperITK->GetLargestPossibleRegion()) ||
114 !lowerITK->GetLargestPossibleRegion().IsInside(result->GetLargestPossibleRegion()))
117 MITK_ERROR <<
"The regions of the slices for the 2D interpolation are not equally sized!";
121 float weight[2] = {1.0f - ratio, ratio};
123 while (!lowerIter.IsAtEnd())
125 typename DistanceFilterImageType::PixelType lowerPixelVal = lowerIter.Get();
126 typename DistanceFilterImageType::PixelType upperPixelVal = upperITK->GetPixel(lowerIter.GetIndex());
128 typename DistanceFilterImageType::PixelType intermediatePixelVal =
129 (weight[0] * upperPixelVal + weight[1] * lowerPixelVal > 0 ? 0 : 1);
131 result->SetPixel(lowerIter.GetIndex(),
static_cast<TPixel
>(intermediatePixelVal));
#define AccessFixedDimensionByItk_3(mitkImage, itkImageTypeFunction, dimension, arg1, arg2, arg3)
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
Image::Pointer Interpolate(Image::ConstPointer lowerSlice, unsigned int lowerSliceIndex, Image::ConstPointer upperSlice, unsigned int upperSliceIndex, unsigned int requestedIndex, unsigned int sliceDimension, Image::Pointer resultImage, unsigned int timeStep, Image::ConstPointer referenceImage) override
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.