Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
mitkOpenCVToMitkImageFilter.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 mitkOpenCVToMitkImageFilter_h
14 #define mitkOpenCVToMitkImageFilter_h
15 
16 // mitk includes
17 #include <MitkOpenCVVideoSupportExports.h>
18 #include <mitkCommon.h>
19 #include <mitkImageSource.h>
20 
21 // itk includes
22 #include <itkMacro.h>
23 #include <itkImage.h>
24 
25 // OpenCV includes
26 #include <opencv2/core.hpp>
27 #include <opencv2/core/core_c.h>
28 
29 #include <mutex>
30 
31 namespace mitk
32 {
33 
37  class MITKOPENCVVIDEOSUPPORT_EXPORT OpenCVToMitkImageFilter : public ImageSource
38  {
39  public:
40  typedef itk::RGBPixel< unsigned char > UCRGBPixelType;
41  typedef itk::RGBPixel< unsigned short > USRGBPixelType;
42  typedef itk::RGBPixel< float > FloatRGBPixelType;
43  typedef itk::RGBPixel< double > DoubleRGBPixelType;
44 
48  template <typename TPixel, unsigned int VImageDimension>
49  static Image::Pointer ConvertCVMatToMitkImage(const cv::Mat input);
50 
52  itkFactorylessNewMacro(Self);
53  itkCloneMacro(Self);
54 
58  void SetOpenCVImage(const IplImage* image);
59  //itkGetMacro(OpenCVImage, const IplImage*);
60 
64  void SetOpenCVMat(const cv::Mat& image);
65  itkGetMacro(OpenCVMat, cv::Mat);
66 
67  OutputImageType* GetOutput(void);
68 
69  //##Documentation
70  //## @brief Convenient method to insert an openCV image as a slice at a
71  //## certain time step into a 3D or 4D mitk::Image.
72  //##
73  //## @param openCVImage - the image that is inserted into the mitk Image
74  //## @param mitkImage - pointer to the mitkImage, which is changed by this method!
75  //## @param timeStep - the time step, at which the openCVImage is inserted
76  //##
77  //## @attention The parameter mitkImage will be changed!
78  void InsertOpenCVImageAsMitkTimeSlice(const cv::Mat openCVImage, Image::Pointer mitkImage, int timeStep);
79 
80  protected:
81 
82  OpenCVToMitkImageFilter(); // purposely hidden
83  ~OpenCVToMitkImageFilter() override;
84 
85  void GenerateData() override;
86 
87  protected:
89  cv::Mat m_OpenCVMat;
90 
91  std::mutex m_ImageMutex;
92  std::mutex m_OpenCVMatMutex;
93  };
94 
95 } // namespace mitk
96 
97 #endif
mitk::OpenCVToMitkImageFilter::m_Image
Image::Pointer m_Image
Definition: mitkOpenCVToMitkImageFilter.h:88
mitk::ImageSource
Superclass of all classes generating Images (instances of class Image) as output.
Definition: mitkImageSource.h:36
mitk::OpenCVToMitkImageFilter
Filter for creating MITK RGB Images from an OpenCV image.
Definition: mitkOpenCVToMitkImageFilter.h:37
mitk::OpenCVToMitkImageFilter::m_ImageMutex
std::mutex m_ImageMutex
Definition: mitkOpenCVToMitkImageFilter.h:91
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
itk::SmartPointer< Self >
mitk::OpenCVToMitkImageFilter::FloatRGBPixelType
itk::RGBPixel< float > FloatRGBPixelType
Definition: mitkOpenCVToMitkImageFilter.h:42
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::BaseDataSource
Superclass of all classes generating some kind of mitk::BaseData.
Definition: mitkBaseDataSource.h:71
mitk::OpenCVToMitkImageFilter::m_OpenCVMat
cv::Mat m_OpenCVMat
Definition: mitkOpenCVToMitkImageFilter.h:89
mitkCommon.h
mitk::OpenCVToMitkImageFilter::USRGBPixelType
itk::RGBPixel< unsigned short > USRGBPixelType
Definition: mitkOpenCVToMitkImageFilter.h:41
mitk::OpenCVToMitkImageFilter::DoubleRGBPixelType
itk::RGBPixel< double > DoubleRGBPixelType
Definition: mitkOpenCVToMitkImageFilter.h:43
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::OpenCVToMitkImageFilter::UCRGBPixelType
itk::RGBPixel< unsigned char > UCRGBPixelType
Definition: mitkOpenCVToMitkImageFilter.h:40
mitkImageSource.h
mitk::OpenCVToMitkImageFilter::m_OpenCVMatMutex
std::mutex m_OpenCVMatMutex
Definition: mitkOpenCVToMitkImageFilter.h:92