26 #include <itkImageRegionConstIterator.h>
27 #include <itkImageSliceIteratorWithIndex.h>
44 m_Image = imageOperation->
GetImage();
52 if (m_SliceDifferenceImage->GetDimension() == 2)
56 switch (m_SliceDimension)
73 if (m_SliceDifferenceImage->GetDimension() != 2 || (m_Image->GetDimension() < 3 || m_Image->GetDimension() > 4) ||
74 m_SliceDifferenceImage->GetDimension(0) != m_Image->GetDimension(m_Dimension0) ||
75 m_SliceDifferenceImage->GetDimension(1) != m_Image->GetDimension(m_Dimension1) ||
76 m_SliceIndex >= m_Image->GetDimension(m_SliceDimension))
79 "Slice and image dimensions differ or slice index is too large. Sorry, cannot work like this.");
83 if (m_Image->GetDimension() == 4)
86 timeSelector->SetInput(m_Image);
87 timeSelector->SetTimeNr(m_TimeStep);
88 timeSelector->UpdateLargestPossibleRegion();
89 image3D = timeSelector->GetOutput();
95 if (m_Factor == 1 || m_Factor == -1)
109 interpolator->
SetChangedSlice(m_SliceDifferenceImage, m_SliceDimension, m_SliceIndex, m_TimeStep);
131 else if (m_SliceDifferenceImage->GetDimension() == 3)
134 if (m_SliceDifferenceImage->GetDimension(0) != m_Image->GetDimension(0) ||
135 m_SliceDifferenceImage->GetDimension(1) != m_Image->GetDimension(1) ||
136 m_SliceDifferenceImage->GetDimension(2) != m_Image->GetDimension(2) || m_TimeStep >= m_Image->GetDimension(3))
138 itkExceptionMacro(
"Diff image size differs from original image size. Sorry, cannot work like this.");
142 if (m_Image->GetDimension() == 4)
145 timeSelector->SetInput(m_Image);
146 timeSelector->SetTimeNr(m_TimeStep);
147 timeSelector->UpdateLargestPossibleRegion();
148 image3D = timeSelector->GetOutput();
154 if (m_Factor == 1 || m_Factor == -1)
192 itkExceptionMacro(
"Diff image must be 2D or 3D. Sorry, cannot work like this.");
198 m_SliceDifferenceImage =
nullptr;
209 #define myMITKDiffImageApplierFilterAccessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension, itkimage2) \
210 if (typeId == MapPixelComponentType<pixeltype>::value) \
213 typedef itk::Image<pixeltype, dimension> ImageType; \
214 typedef mitk::ImageToItk<ImageType> ImageToItkType; \
215 itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New(); \
216 const mitk::Image *constImage = mitkImage; \
217 mitk::Image *nonConstImage = const_cast<mitk::Image *>(constImage); \
218 nonConstImage->Update(); \
219 imagetoitk->SetInput(nonConstImage); \
220 imagetoitk->Update(); \
221 itkImageTypeFunction(imagetoitk->GetOutput(), itkimage2); \
225 #define myMITKDiffImageApplierFilterAccessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension, itkimage2) \
228 myMITKDiffImageApplierFilterAccessByItk(mitkImage, itkImageTypeFunction, double, dimension, itkimage2) else myMITKDiffImageApplierFilterAccessByItk( \
230 itkImageTypeFunction, \
233 itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, itkImageTypeFunction, int, dimension, itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, \
234 itkImageTypeFunction, \
237 itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, itkImageTypeFunction, short, dimension, itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, itkImageTypeFunction, unsigned short, dimension, itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, \
238 itkImageTypeFunction, \
241 itkimage2) else myMITKDiffImageApplierFilterAccessByItk(mitkImage, \
242 itkImageTypeFunction, \
249 template <
typename TPixel,
unsigned int VImageDimension>
252 const int typeId = m_SliceDifferenceImage->GetPixelType().GetComponentType();
257 template <
typename TPixel,
unsigned int VImageDimension>
260 const int typeId = m_SliceDifferenceImage->GetPixelType().GetComponentType();
265 template <
typename TPixel1,
unsigned int VImageDimension1,
typename TPixel2,
unsigned int VImageDimension2>
267 itk::Image<TPixel2, VImageDimension2> *outputImage)
269 typedef itk::Image<TPixel1, VImageDimension1> DiffImageType;
270 typedef itk::Image<TPixel2, VImageDimension2> VolumeImageType;
272 typedef itk::ImageSliceIteratorWithIndex<VolumeImageType> OutputSliceIteratorType;
273 typedef itk::ImageRegionConstIterator<DiffImageType> DiffSliceIteratorType;
275 typename VolumeImageType::RegionType sliceInVolumeRegion;
277 sliceInVolumeRegion = outputImage->GetLargestPossibleRegion();
278 sliceInVolumeRegion.SetSize(m_SliceDimension, 1);
279 sliceInVolumeRegion.SetIndex(m_SliceDimension, m_SliceIndex);
281 OutputSliceIteratorType outputIterator(outputImage, sliceInVolumeRegion);
282 outputIterator.SetFirstDirection(m_Dimension0);
283 outputIterator.SetSecondDirection(m_Dimension1);
285 DiffSliceIteratorType diffIterator(diffImage, diffImage->GetLargestPossibleRegion());
288 outputIterator.GoToBegin();
289 diffIterator.GoToBegin();
290 while (!outputIterator.IsAtEnd())
292 while (!outputIterator.IsAtEndOfSlice())
294 while (!outputIterator.IsAtEndOfLine())
296 TPixel2 newValue = outputIterator.Get() + (TPixel2)((
double)diffIterator.Get() * m_Factor);
297 outputIterator.Set(newValue);
301 outputIterator.NextLine();
303 outputIterator.NextSlice();
307 template <
typename TPixel1,
unsigned int VImageDimension1,
typename TPixel2,
unsigned int VImageDimension2>
309 itk::Image<TPixel2, VImageDimension2> *outputImage)
311 typedef itk::Image<TPixel1, VImageDimension1> DiffImageType;
312 typedef itk::Image<TPixel2, VImageDimension2> VolumeImageType;
314 typedef itk::ImageRegionIterator<VolumeImageType> OutputSliceIteratorType;
315 typedef itk::ImageRegionConstIterator<DiffImageType> DiffSliceIteratorType;
317 OutputSliceIteratorType outputIterator(outputImage, outputImage->GetLargestPossibleRegion());
318 DiffSliceIteratorType diffIterator(diffImage, diffImage->GetLargestPossibleRegion());
321 outputIterator.GoToBegin();
322 diffIterator.GoToBegin();
323 while (!outputIterator.IsAtEnd())
325 TPixel2 newValue = outputIterator.Get() + (TPixel2)((
double)diffIterator.Get() * m_Factor);
326 outputIterator.Set(newValue);
332 template <
typename TPixel,
unsigned int VImageDimension>
335 typedef itk::ImageRegionIterator<itk::Image<TPixel, VImageDimension>> IteratorType;
336 IteratorType iter(itkImage, itkImage->GetLargestPossibleRegion());
339 while (!iter.IsAtEnd())
341 iter.Set(-(iter.Get()));
Operation, that holds information about some image difference.
void ItkImageProcessing2DDiff(itk::Image< TPixel1, VImageDimension1 > *itkImage1, itk::Image< TPixel2, VImageDimension2 > *itkImage2)
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
Base class of all Operation-classes.
unsigned int GetTimeStep()
void ItkImageSwitch3DDiff(itk::Image< TPixel, VImageDimension > *image)
void SetChangedSlice(const Image *sliceDiff, unsigned int sliceDimension, unsigned int sliceIndex, unsigned int timeStep)
Update after changing a single slice.
Generates interpolations of 2D slices.
void ItkImageSwitch2DDiff(itk::Image< TPixel, VImageDimension > *image)
virtual ~DiffImageApplier()
Applies difference images to 3D images.
void ItkImageProcessing3DDiff(itk::Image< TPixel1, VImageDimension1 > *itkImage1, itk::Image< TPixel2, VImageDimension2 > *itkImage2)
void BlockModified(bool)
Block reaction to an images Modified() events.
unsigned int GetSliceDimension()
static DiffImageApplier * GetInstanceForUndo()
void SetChangedVolume(const Image *sliceDiff, unsigned int timeStep)
static RenderingManager * GetInstance()
static SegmentationInterpolationController * InterpolatorForImage(const Image *)
Find interpolator for a given image.
virtual void ExecuteOperation(Operation *operation) override
unsigned int GetSliceIndex()
Image::Pointer GetDiffImage()
#define myMITKDiffImageApplierFilterAccessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension, itkimage2)
void ItkInvertPixelValues(itk::Image< TPixel, VImageDimension > *itkImage)
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)