Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkOpenCVToMitkImageFilter_h
18 #define mitkOpenCVToMitkImageFilter_h
19 
20 // mitk includes
21 #include <MitkOpenCVVideoSupportExports.h>
22 #include <mitkCommon.h>
23 #include <mitkImageSource.h>
24 
25 // itk includes
26 #include <itkMacro.h>
27 #include <itkFastMutexLock.h>
28 #include <itkImage.h>
29 
30 // OpenCV includes
31 #include <cv.h>
32 
33 namespace mitk
34 {
35 
39  class MITKOPENCVVIDEOSUPPORT_EXPORT OpenCVToMitkImageFilter : public ImageSource
40  {
41  public:
42  typedef itk::RGBPixel< unsigned char > UCRGBPixelType;
43  typedef itk::RGBPixel< unsigned short > USRGBPixelType;
44  typedef itk::RGBPixel< float > FloatRGBPixelType;
45  typedef itk::RGBPixel< double > DoubleRGBPixelType;
46 
50  template <typename TPixel, unsigned int VImageDimension>
51  static Image::Pointer ConvertCVMatToMitkImage(const cv::Mat input);
52 
54  itkFactorylessNewMacro(Self)
55  itkCloneMacro(Self)
56 
60  void SetOpenCVImage(const IplImage* image);
61  //itkGetMacro(OpenCVImage, const IplImage*);
62 
66  void SetOpenCVMat(const cv::Mat& image);
67  itkGetMacro(OpenCVMat, cv::Mat);
68 
69  OutputImageType* GetOutput(void);
70 
71  //##Documentation
72  //## @brief Convenient method to insert an openCV image as a slice at a
73  //## certain time step into a 3D or 4D mitk::Image.
74  //##
75  //## @param openCVImage - the image that is inserted into the mitk Image
76  //## @param mitkImage - pointer to the mitkImage, which is changed by this method!
77  //## @param timeStep - the time step, at which the openCVImage is inserted
78  //##
79  //## @attention The parameter mitkImage will be changed!
80  void InsertOpenCVImageAsMitkTimeSlice(const cv::Mat openCVImage, Image::Pointer mitkImage, int timeStep);
81 
82  protected:
83 
84  OpenCVToMitkImageFilter(); // purposely hidden
85  virtual ~OpenCVToMitkImageFilter();
86 
87  virtual void GenerateData() override;
88 
89  protected:
90  Image::Pointer m_Image;
91  cv::Mat m_OpenCVMat;
92 
93  itk::FastMutexLock::Pointer m_ImageMutex;
94  itk::FastMutexLock::Pointer m_OpenCVMatMutex;
95  };
96 
97 } // namespace mitk
98 
99 #endif // mitkOpenCVToMitkImageFilter_h
Superclass of all classes generating Images (instances of class Image) as output. ...
Superclass of all classes generating some kind of mitk::BaseData.
DataCollection - Class to facilitate loading/accessing structured data.
itk::RGBPixel< double > DoubleRGBPixelType
itk::RGBPixel< unsigned char > UCRGBPixelType
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Filter for creating MITK RGB Images from an OpenCV image.
Image class for storing images.
Definition: mitkImage.h:76
itk::RGBPixel< unsigned short > USRGBPixelType