19 #include <itkImportImageFilter.h>
20 #include <itkRGBPixel.h>
22 #include <itkOpenCVImageBridge.h>
23 #include <itkImageFileWriter.h>
49 const cv::Mat cvMat = cv::Mat(image);
64 if ((input.depth() >= 0) && ((
unsigned int)input.depth() == CV_8S) && (input.channels() == 1))
66 m_Image = ConvertCVMatToMitkImage< char, 2>(input);
68 else if (input.depth() == CV_8U && input.channels() == 1)
70 m_Image = ConvertCVMatToMitkImage< unsigned char, 2>(input);
72 else if (input.depth() == CV_8U && input.channels() == 3)
74 m_Image = ConvertCVMatToMitkImage< UCRGBPixelType, 2>(input);
76 else if (input.depth() == CV_16U && input.channels() == 1)
78 m_Image = ConvertCVMatToMitkImage< unsigned short, 2>(input);
80 else if (input.depth() == CV_16U && input.channels() == 3)
82 m_Image = ConvertCVMatToMitkImage< USRGBPixelType, 2>(input);
84 else if (input.depth() == CV_32F && input.channels() == 1)
86 m_Image = ConvertCVMatToMitkImage< float, 2>(input);
88 else if (input.depth() == CV_32F && input.channels() == 3)
90 m_Image = ConvertCVMatToMitkImage< FloatRGBPixelType, 2>(input);
92 else if (input.depth() == CV_64F && input.channels() == 1)
94 m_Image = ConvertCVMatToMitkImage< double, 2>(input);
96 else if (input.depth() == CV_64F && input.channels() == 3)
98 m_Image = ConvertCVMatToMitkImage< DoubleRGBPixelType, 2>(input);
102 MITK_WARN <<
"Unknown image depth and/or pixel type. Cannot convert OpenCV to MITK image.";
110 MITK_WARN <<
"Cannot start filter. OpenCV Image not set.";
123 template <
typename TPixel,
unsigned int VImageDimension>
126 typedef itk::Image< TPixel, VImageDimension >
ImageType;
128 typename ImageType::Pointer output = itk::OpenCVImageBridge::CVMatToITKImage<ImageType>(input);
144 mitkImage->GetGeometry(timeStep)->SetSpacing(this->
GetOutput()->GetGeometry()->GetSpacing());
145 mitkImage->GetGeometry(timeStep)->SetOrigin(this->
GetOutput()->GetGeometry()->GetOrigin());
146 mitkImage->GetGeometry(timeStep)->SetIndexToWorldTransform(this->
GetOutput()->GetGeometry()->GetIndexToWorldTransform());
149 mitkImage->Modified();
itk::SmartPointer< Self > Pointer
void InsertOpenCVImageAsMitkTimeSlice(const cv::Mat openCVImage, Image::Pointer mitkImage, int timeStep)
Convenient method to insert an openCV image as a slice at a certain time step into a 3D or 4D mitk::I...
static void Update(vtkPolyData *)
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
DataCollection - Class to facilitate loading/accessing structured data.
virtual ~OpenCVToMitkImageFilter()
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
OpenCVToMitkImageFilter()
itk::FastMutexLock::Pointer m_ImageMutex
T::Pointer GetData(const std::string &name)
OutputImageType * GetOutput(void)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
void SetOpenCVImage(const IplImage *image)
Image class for storing images.
itk::FastMutexLock::Pointer m_OpenCVMatMutex
static Image::Pointer ConvertCVMatToMitkImage(const cv::Mat input)
void SetOpenCVMat(const cv::Mat &image)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.