Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 <itkFastMutexLock.h>
24 #include <itkImage.h>
25 
26 // OpenCV includes
27 #include <opencv2/core.hpp>
28 
29 namespace mitk
30 {
31 
35  class MITKOPENCVVIDEOSUPPORT_EXPORT OpenCVToMitkImageFilter : public ImageSource
36  {
37  public:
38  typedef itk::RGBPixel< unsigned char > UCRGBPixelType;
39  typedef itk::RGBPixel< unsigned short > USRGBPixelType;
40  typedef itk::RGBPixel< float > FloatRGBPixelType;
41  typedef itk::RGBPixel< double > DoubleRGBPixelType;
42 
46  template <typename TPixel, unsigned int VImageDimension>
47  static Image::Pointer ConvertCVMatToMitkImage(const cv::Mat input);
48 
50  itkFactorylessNewMacro(Self);
51  itkCloneMacro(Self);
52 
56  void SetOpenCVImage(const IplImage* image);
57  //itkGetMacro(OpenCVImage, const IplImage*);
58 
62  void SetOpenCVMat(const cv::Mat& image);
63  itkGetMacro(OpenCVMat, cv::Mat);
64 
65  OutputImageType* GetOutput(void);
66 
67  //##Documentation
68  //## @brief Convenient method to insert an openCV image as a slice at a
69  //## certain time step into a 3D or 4D mitk::Image.
70  //##
71  //## @param openCVImage - the image that is inserted into the mitk Image
72  //## @param mitkImage - pointer to the mitkImage, which is changed by this method!
73  //## @param timeStep - the time step, at which the openCVImage is inserted
74  //##
75  //## @attention The parameter mitkImage will be changed!
76  void InsertOpenCVImageAsMitkTimeSlice(const cv::Mat openCVImage, Image::Pointer mitkImage, int timeStep);
77 
78  protected:
79 
80  OpenCVToMitkImageFilter(); // purposely hidden
81  ~OpenCVToMitkImageFilter() override;
82 
83  void GenerateData() override;
84 
85  protected:
87  cv::Mat m_OpenCVMat;
88 
89  itk::FastMutexLock::Pointer m_ImageMutex;
90  itk::FastMutexLock::Pointer m_OpenCVMatMutex;
91  };
92 
93 } // namespace mitk
94 
95 #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::FastMutexLock::Pointer m_ImageMutex
itk::RGBPixel< unsigned char > UCRGBPixelType
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
Filter for creating MITK RGB Images from an OpenCV image.
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
itk::FastMutexLock::Pointer m_OpenCVMatMutex
itk::RGBPixel< unsigned short > USRGBPixelType