Filter for creating MITK RGB Images from an OpenCV image. More...
#include <mitkOpenCVToMitkImageFilter.h>
Public Types | |
typedef itk::RGBPixel < unsigned char > | UCRGBPixelType |
typedef itk::RGBPixel < unsigned short > | USRGBPixelType |
typedef itk::RGBPixel< float > | FloatRGBPixelType |
typedef itk::RGBPixel< double > | DoubleRGBPixelType |
typedef OpenCVToMitkImageFilter | Self |
typedef ImageSource | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetOpenCVImage (const IplImage *_arg) |
virtual const IplImage * | GetOpenCVImage () |
virtual DataObjectPointer | MakeOutput (unsigned int idx) |
Make a DataObject of the correct type to used as the specified output. | |
OutputImageType * | GetOutput (unsigned int idx) |
Static Public Member Functions | |
template<typename TPixel , unsigned int VImageDimension> | |
static mitk::Image::Pointer | ConvertIplToMitkImage (const IplImage *input, bool copyBuffer=true) |
static Pointer | New () |
Method for creation through the object factory. | |
Protected Member Functions | |
OpenCVToMitkImageFilter () | |
virtual | ~OpenCVToMitkImageFilter () |
virtual void | GenerateData () |
A version of GenerateData() specific for image processing filters. | |
Protected Attributes | |
mitk::Image::Pointer | m_Image |
const IplImage * | m_OpenCVImage |
Filter for creating MITK RGB Images from an OpenCV image.
Last contributor:
Definition at line 38 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::SmartPointer<const Self> mitk::OpenCVToMitkImageFilter::ConstPointer |
Definition at line 49 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::RGBPixel< double > mitk::OpenCVToMitkImageFilter::DoubleRGBPixelType |
Definition at line 44 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::RGBPixel< float > mitk::OpenCVToMitkImageFilter::FloatRGBPixelType |
Definition at line 43 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::SmartPointer<Self> mitk::OpenCVToMitkImageFilter::Pointer |
Definition at line 49 of file mitkOpenCVToMitkImageFilter.h.
Definition at line 49 of file mitkOpenCVToMitkImageFilter.h.
Definition at line 49 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::RGBPixel< unsigned char > mitk::OpenCVToMitkImageFilter::UCRGBPixelType |
Definition at line 41 of file mitkOpenCVToMitkImageFilter.h.
typedef itk::RGBPixel< unsigned short > mitk::OpenCVToMitkImageFilter::USRGBPixelType |
Definition at line 42 of file mitkOpenCVToMitkImageFilter.h.
mitk::OpenCVToMitkImageFilter::OpenCVToMitkImageFilter | ( | ) | [protected] |
Definition at line 24 of file mitkOpenCVToMitkImageFilter.cpp.
: m_OpenCVImage(0) { }
mitk::OpenCVToMitkImageFilter::~OpenCVToMitkImageFilter | ( | ) | [protected, virtual] |
Definition at line 29 of file mitkOpenCVToMitkImageFilter.cpp.
{ }
mitk::Image::Pointer mitk::OpenCVToMitkImageFilter::ConvertIplToMitkImage | ( | const IplImage * | input, |
bool | copyBuffer = true |
||
) | [static] |
Definition at line 91 of file mitkOpenCVToMitkImageFilter.cpp.
References mitk::ImportItkImage().
{ mitk::Image::Pointer mitkImage(0); typedef itk::Image< TPixel, VImageDimension > ItkImage; typedef itk::ImportImageFilter< TPixel, VImageDimension > ImportFilterType; typename ImportFilterType::Pointer importFilter = ImportFilterType::New(); typename ImportFilterType::SizeType size; size[0] = input->width; size[1] = input->height; typename ImportFilterType::IndexType start; start.Fill( 0 ); typename ImportFilterType::RegionType region; region.SetIndex( start ); region.SetSize( size ); importFilter->SetRegion( region ); double origin[ VImageDimension ]; origin[0] = 0.0; // X coordinate origin[1] = 0.0; // Y coordinate importFilter->SetOrigin( origin ); double spacing[ VImageDimension ]; spacing[0] = 1.0; // along X direction spacing[1] = 1.0; // along Y direction importFilter->SetSpacing( spacing ); const unsigned int numberOfPixels = size[0] * size[1]; const unsigned int numberOfBytes = numberOfPixels * sizeof( TPixel ); if( copyBuffer ) { const bool importImageFilterWillOwnTheBuffer = false; TPixel * localBuffer = new TPixel[numberOfPixels]; memcpy(localBuffer, input->imageData, numberOfBytes); importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer ); } else { const bool importImageFilterWillOwnTheBuffer = false; TPixel * localBuffer = reinterpret_cast< TPixel * >( input->imageData ); importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer ); } importFilter->Update(); typename ItkImage::Pointer output = importFilter->GetOutput(); output->DisconnectPipeline(); mitkImage = mitk::ImportItkImage( output ); return mitkImage; }
void mitk::OpenCVToMitkImageFilter::GenerateData | ( | ) | [protected, virtual] |
A version of GenerateData() specific for image processing filters.
This implementation will split the processing across multiple threads. The buffer is allocated by this method. Then the BeforeThreadedGenerateData() method is called (if provided). Then, a series of threads are spawned each calling ThreadedGenerateData(). After all the threads have completed processing, the AfterThreadedGenerateData() method is called (if provided). If an image processing filter cannot be threaded, the filter should provide an implementation of GenerateData(). That implementation is responsible for allocating the output buffer. If a filter an be threaded, it should NOT provide a GenerateData() method but should provide a ThreadedGenerateData() instead.
Reimplemented from mitk::ImageSource.
Definition at line 33 of file mitkOpenCVToMitkImageFilter.cpp.
References MITK_WARN.
{ if(m_OpenCVImage == 0) { MITK_WARN << "Cannot not start filter. OpenCV Image not set."; return; } // convert to rgb image color space IplImage* rgbOpenCVImage = cvCreateImage( cvSize( m_OpenCVImage->width, m_OpenCVImage->height ) , m_OpenCVImage->depth, m_OpenCVImage->nChannels ); if( m_OpenCVImage->nChannels == 3) cvCvtColor( m_OpenCVImage, rgbOpenCVImage, CV_BGR2RGB ); // now convert rgb image if( (m_OpenCVImage->depth>=0) && ((unsigned int)m_OpenCVImage->depth == IPL_DEPTH_8S) && (m_OpenCVImage->nChannels == 1) ) m_Image = ConvertIplToMitkImage< char, 2>( m_OpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_8U && m_OpenCVImage->nChannels == 1 ) m_Image = ConvertIplToMitkImage< unsigned char, 2>( m_OpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_8U && m_OpenCVImage->nChannels == 3 ) m_Image = ConvertIplToMitkImage< UCRGBPixelType, 2>( rgbOpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_16U && m_OpenCVImage->nChannels == 1 ) m_Image = ConvertIplToMitkImage< unsigned short, 2>( m_OpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_16U && m_OpenCVImage->nChannels == 3 ) m_Image = ConvertIplToMitkImage< USRGBPixelType, 2>( rgbOpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_32F && m_OpenCVImage->nChannels == 1 ) m_Image = ConvertIplToMitkImage< float, 2>( m_OpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_32F && m_OpenCVImage->nChannels == 3 ) m_Image = ConvertIplToMitkImage< FloatRGBPixelType , 2>( rgbOpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_64F && m_OpenCVImage->nChannels == 1 ) m_Image = ConvertIplToMitkImage< double, 2>( m_OpenCVImage ); else if( m_OpenCVImage->depth == IPL_DEPTH_64F && m_OpenCVImage->nChannels == 3 ) m_Image = ConvertIplToMitkImage< DoubleRGBPixelType , 2>( rgbOpenCVImage ); }
virtual const char* mitk::OpenCVToMitkImageFilter::GetClassName | ( | ) | const [virtual] |
virtual const IplImage* mitk::OpenCVToMitkImageFilter::GetOpenCVImage | ( | ) | [virtual] |
mitk::ImageSource::OutputImageType * mitk::OpenCVToMitkImageFilter::GetOutput | ( | unsigned int | idx ) |
Reimplemented from mitk::ImageSource.
Definition at line 82 of file mitkOpenCVToMitkImageFilter.cpp.
{ return m_Image; }
mitk::ImageSource::DataObjectPointer mitk::OpenCVToMitkImageFilter::MakeOutput | ( | unsigned int | idx ) | [virtual] |
Make a DataObject of the correct type to used as the specified output.
Every ProcessObject subclass must be able to create a DataObject that can be used as a specified output. This method is automatically called when DataObject::DisconnectPipeline() is called. DataObject::DisconnectPipeline, disconnects a data object from being an output of its current source. When the data object is disconnected, the ProcessObject needs to construct a replacement output data object so that the ProcessObject is in a valid state. So DataObject::DisconnectPipeline eventually calls ProcessObject::MakeOutput. Note that MakeOutput always returns a SmartPointer to a DataObject. If a subclass of ImageSource has multiple outputs of different types, then that class must provide an implementation of MakeOutput().
Reimplemented from mitk::ImageSource.
Definition at line 77 of file mitkOpenCVToMitkImageFilter.cpp.
{ return Superclass::MakeOutput(idx); }
static Pointer mitk::OpenCVToMitkImageFilter::New | ( | ) | [static] |
Method for creation through the object factory.
Reimplemented from mitk::ImageSource.
virtual void mitk::OpenCVToMitkImageFilter::SetOpenCVImage | ( | const IplImage * | _arg ) | [virtual] |
Definition at line 66 of file mitkOpenCVToMitkImageFilter.h.
const IplImage* mitk::OpenCVToMitkImageFilter::m_OpenCVImage [protected] |
Definition at line 67 of file mitkOpenCVToMitkImageFilter.h.