Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkImageToItk.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkImageToItk_h
14 #define mitkImageToItk_h
15 
16 #include <mitkImage.h>
17 #include <mitkImageDataItem.h>
18 #include <mitkImageWriteAccessor.h>
19 
20 #include <itkImage.h>
21 #include <itkImageSource.h>
22 
23 namespace mitk
24 {
32  template <class TOutputImage>
33  class ImageToItk : public itk::ImageSource<TOutputImage>
34  {
35  protected:
36  mitk::Image::Pointer m_MitkImage;
37  mitk::ImageDataItem::Pointer m_ImageDataItem;
38 
39  public:
40  typedef ImageToItk Self;
41  typedef itk::ImageSource<TOutputImage> Superclass;
44 
46  itkFactorylessNewMacro(Self);
47  itkCloneMacro(Self);
48 
50  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
51 
54  typedef InputImageType::Pointer InputImagePointer;
55  typedef InputImageType::ConstPointer InputImageConstPointer;
57  typedef typename TOutputImage::SizeType SizeType;
58  typedef typename TOutputImage::IndexType IndexType;
59  typedef typename TOutputImage::RegionType RegionType;
60  typedef typename TOutputImage::PixelType PixelType;
61  typedef typename TOutputImage::InternalPixelType InternalPixelType;
62  typedef typename TOutputImage::PixelContainer PixelContainer;
63 
71  virtual void SetInput(mitk::Image *input);
72 
80  virtual void SetInput(const mitk::Image *input);
81 
83  void UpdateOutputInformation() override;
84 
86  itkGetMacro(Channel, int);
88  itkSetMacro(Channel, int);
89 
91  itkSetMacro(CopyMemFlag, bool);
93  itkGetMacro(CopyMemFlag, bool);
95  itkBooleanMacro(CopyMemFlag);
96 
98  itkSetMacro(Options, int);
100  itkGetMacro(Options, int);
101 
102  protected:
103  using itk::ProcessObject::SetInput;
104 
107 
109  const mitk::Image *GetInput() const;
110 
111  ImageToItk() : m_CopyMemFlag(false), m_Channel(0), m_Options(mitk::ImageAccessorBase::DefaultBehavior) {}
112  ~ImageToItk() override {}
113 
115  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
116 
118  void GenerateData() override;
119 
121  void GenerateOutputInformation() override;
122 
123  private:
124  bool m_CopyMemFlag;
125  int m_Channel;
126  int m_Options;
127 
128  bool m_ConstInput;
129 
130  // ImageToItk(const Self&); //purposely not implemented
131  void operator=(const Self &); // purposely not implemented
132 
133  void CheckInput(const mitk::Image *image) const;
134  };
135 
160  template <typename TPixel, unsigned int VDimension>
162  {
163  typedef typename ImageTypeTrait<TPixel, VDimension>::ImageType ImageType;
164  typedef mitk::ImageToItk<ImageType> ImageToItkType;
165  itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();
166  imagetoitk->SetInput(mitkImage);
167  imagetoitk->Update();
168  return imagetoitk->GetOutput();
169  }
170 
195  template <typename TPixel, unsigned int VDimension>
197  {
198  typedef typename ImageTypeTrait<TPixel, VDimension>::ImageType ImageType;
199  typedef mitk::ImageToItk<ImageType> ImageToItkType;
200  itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();
201  imagetoitk->SetInput(mitkImage);
202  imagetoitk->Update();
203  return imagetoitk->GetOutput();
204  }
205 
206 } // end namespace mitk
207 
208 #ifndef ITK_MANUAL_INSTANTIATION
209 #include <mitkImageToItk.tpp>
210 #endif
211 
212 #endif
TOutputImage::RegionType RegionType
TOutputImage::PixelContainer PixelContainer
Superclass::OutputImageRegionType OutputImageRegionType
Superclass typedefs.
mitk::Image::Pointer m_MitkImage
itk::SmartPointer< Self > Pointer
void GenerateOutputInformation() override
Set up the output information (size, spacing, origin, direction) from the MITK image.
itk::ImageSource< TOutputImage > Superclass
mitk::ImageDataItem::Pointer m_ImageDataItem
void GenerateData() override
Generate the ITK image data from the MITK image input.
void UpdateOutputInformation() override
Update the output information from the MITK image.
TOutputImage::IndexType IndexType
~ImageToItk() override
virtual void SetInput(mitk::Image *input)
Set the MITK image as input (non-const version).
TOutputImage::PixelType PixelType
InputImageType::ConstPointer InputImageConstPointer
SlicedData::RegionType InputImageRegionType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Print self information to the given stream.
const mitk::Image * GetInput() const
Get the MITK image input (const).
TOutputImage::InternalPixelType InternalPixelType
mitk::Image InputImageType
Some convenient typedefs.
itk::SmartPointer< const Self > ConstPointer
mitk::Image * GetInput(void)
Get the MITK image input (non-const).
virtual void SetInput(const mitk::Image *input)
Set the MITK image as input (const version).
TOutputImage::SizeType SizeType
InputImageType::Pointer InputImagePointer
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
itk::ImageRegion< RegionDimension > RegionType
ImageTypeTrait< TPixel, VDimension >::ImageType::Pointer ImageToItkImage(mitk::Image *mitkImage)
Convert a MITK image to an ITK image.
Find image slices visible on a given plane.
Compile-time trait that maps a pixel type and dimension to the corresponding ITK image type.
itk::Image< TPixelType, VDimension > ImageType