Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitk::PhotoacousticMotionCorrectionFilter Class Reference

Class implementing a mitk::ImageToImageFilter for PAUS motion correction. More...

#include <mitkPhotoacousticMotionCorrectionFilter.h>

Inheritance diagram for mitk::PhotoacousticMotionCorrectionFilter:
Collaboration diagram for mitk::PhotoacousticMotionCorrectionFilter:

Public Member Functions

 mitkClassMacro (PhotoacousticMotionCorrectionFilter, ImageToImageFilter)
 
virtual void SetBatchSize (unsigned int _arg)
 
virtual void SetPyrScale (double _arg)
 
virtual void SetLevels (unsigned int _arg)
 
virtual void SetWinSize (unsigned int _arg)
 
virtual void SetIterations (unsigned int _arg)
 
virtual void SetPolyN (unsigned int _arg)
 
virtual void SetPolySigma (double _arg)
 
virtual void SetFlags (unsigned int _arg)
 
virtual unsigned int GetBatchSize () const
 
virtual double GetPyrScale () const
 
virtual unsigned int GetLevels () const
 
virtual unsigned int GetWinSize () const
 
virtual unsigned int GetIterations () const
 
virtual unsigned int GetPolyN () const
 
virtual double GetPolySigma () const
 
virtual unsigned int GetFlags () const
 
void SetPaInput (mitk::Image::Pointer)
 Wrapper which sets the photoacoustic image as the correct input. More...
 
mitk::Image::Pointer GetPaInput ()
 Wrapper which gets the photoacoustic image out of the correct input. More...
 
void SetUsInput (mitk::Image::Pointer)
 Wrapper which sets the ultrasonic image as the correct input. More...
 
mitk::Image::Pointer GetUsInput ()
 Wrapper which gets the ultrasonic image out of the correct input. More...
 
mitk::Image::Pointer GetPaOutput ()
 Wrapper which gets the photoacoustic image out of the correct output. More...
 
mitk::Image::Pointer GetUsOutput ()
 Wrapper which gets the ultrasonic image out of the correct output. More...
 
- Public Member Functions inherited from mitk::ImageToImageFilter
virtual std::vector< std::string > GetClassHierarchy () const override
 
virtual const char * GetClassName () const
 
Pointer Clone () const
 
virtual void SetInput (const InputImageType *image)
 
virtual void SetInput (unsigned int, const InputImageType *image)
 
InputImageTypeGetInput (void)
 
InputImageTypeGetInput (unsigned int idx)
 
const InputImageTypeGetInput (void) const
 
const InputImageTypeGetInput (unsigned int idx) const
 
- Public Member Functions inherited from mitk::ImageSource
Pointer Clone () const
 
OutputTypeGetOutput ()
 Get the output data of this image source object. More...
 
const OutputTypeGetOutput () const
 
OutputTypeGetOutput (DataObjectPointerArraySizeType idx)
 
const OutputTypeGetOutput (DataObjectPointerArraySizeType idx) const
 
itk::DataObject::Pointer MakeOutput (DataObjectPointerArraySizeType idx) override
 Make a DataObject of the correct type to used as the specified output. More...
 
itk::DataObject::Pointer MakeOutput (const DataObjectIdentifierType &name) override
 
virtual vtkImageData * GetVtkImageData ()
 
virtual const vtkImageData * GetVtkImageData () const
 
- Public Member Functions inherited from mitk::BaseDataSource
OutputTypeGetOutput ()
 
const OutputTypeGetOutput () const
 
OutputTypeGetOutput (DataObjectPointerArraySizeType idx)
 
const OutputTypeGetOutput (DataObjectPointerArraySizeType idx) const
 
virtual void GraftOutput (OutputType *output)
 Graft the specified BaseData onto this BaseDataSource's output. More...
 
virtual void GraftOutput (const DataObjectIdentifierType &key, OutputType *output)
 
virtual void GraftNthOutput (unsigned int idx, OutputType *output)
 Graft the specified base data object onto this BaseDataSource's idx'th output. More...
 
bool Updating () const
 Access itk::ProcessObject::m_Updating. More...
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from mitk::ImageToImageFilter
static const char * GetStaticNameOfClass ()
 
static Pointer New ()
 
- Static Public Member Functions inherited from mitk::ImageSource
static const char * GetStaticNameOfClass ()
 
static Pointer New ()
 Method for creation through the object factory. More...
 
- Static Public Member Functions inherited from mitk::BaseDataSource
static const char * GetStaticNameOfClass ()
 

Protected Member Functions

 PhotoacousticMotionCorrectionFilter ()
 
 ~PhotoacousticMotionCorrectionFilter () override
 
void GenerateData () override
 Apply OpenCV algorithm to compensate motion in a 2d image time series. More...
 
void CheckInput (mitk::Image::Pointer paImage, mitk::Image::Pointer usImage)
 Validate the input images. More...
 
void InitializeOutputIfNecessary (mitk::Image::Pointer paInput, mitk::Image::Pointer usInput, mitk::Image::Pointer paOutput, mitk::Image::Pointer usOutput)
 Assure that the output images have the same dimensions as the input images. More...
 
void InitializeOutput (mitk::Image::Pointer input, mitk::Image::Pointer output)
 Copy the image data from the input image to the output image. More...
 
void PerformCorrection (mitk::Image::Pointer paInput, mitk::Image::Pointer usInput, mitk::Image::Pointer paOutput, mitk::Image::Pointer usOutput)
 This method performs the actual motion compensation. More...
 
cv::Mat GetMatrix (const mitk::Image::Pointer input, unsigned int i)
 Extract a 2d slice as OpenCV matrix. More...
 
cv::Mat FitMatrixToChar (cv::Mat mat)
 Rescale matrix such that the values lie between 0 and 255. More...
 
void InsertMatrixAsSlice (cv::Mat mat, mitk::Image::Pointer output, unsigned int i)
 Insert a OpenCV matrix as a slice into an image. More...
 
cv::Mat ComputeFlowMap (cv::Mat)
 Compute the remapping map from an optical flow. More...
 
- Protected Member Functions inherited from mitk::ImageToImageFilter
 ImageToImageFilter ()
 
 ~ImageToImageFilter () override
 
void PrintSelf (std::ostream &os, itk::Indent indent) const override
 
void GenerateInputRequestedRegion () override
 
- Protected Member Functions inherited from mitk::ImageSource
 ImageSource ()
 
 ~ImageSource () override
 
void GenerateData () override
 A version of GenerateData() specific for image processing filters. More...
 
virtual void ThreadedGenerateData (const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
 If an imaging filter can be implemented as a multithreaded algorithm, the filter will provide an implementation of ThreadedGenerateData(). More...
 
void PrepareOutputs () override
 This method is intentionally left blank. More...
 
virtual void AllocateOutputs ()
 The GenerateData method normally allocates the buffers for all of the outputs of a filter. More...
 
virtual void BeforeThreadedGenerateData ()
 If an imaging filter needs to perform processing after the buffer has been allocated but before threads are spawned, the filter can can provide an implementation for BeforeThreadedGenerateData(). More...
 
virtual void AfterThreadedGenerateData ()
 If an imaging filter needs to perform processing after all processing threads have completed, the filter can can provide an implementation for AfterThreadedGenerateData(). More...
 
virtual unsigned int SplitRequestedRegion (unsigned int i, unsigned int num, OutputImageRegionType &splitRegion)
 Split the output's RequestedRegion into "num" pieces, returning region "i" as "splitRegion". More...
 
- Protected Member Functions inherited from mitk::BaseDataSource
 BaseDataSource ()
 
 ~BaseDataSource () override
 

Additional Inherited Members

- Public Types inherited from mitk::ImageToImageFilter
typedef ImageToImageFilter Self
 
typedef ImageSource Superclass
 
typedef itk::SmartPointer< SelfPointer
 
typedef itk::SmartPointer< const SelfConstPointer
 
typedef Superclass::OutputImageRegionType OutputImageRegionType
 
typedef mitk::Image InputImageType
 
typedef InputImageType::Pointer InputImagePointer
 
typedef InputImageType::ConstPointer InputImageConstPointer
 
typedef SlicedData::RegionType InputImageRegionType
 
- Public Types inherited from mitk::ImageSource
typedef ImageSource Self
 
typedef BaseDataSource Superclass
 
typedef itk::SmartPointer< SelfPointer
 
typedef itk::SmartPointer< const SelfConstPointer
 
typedef mitk::Image OutputImageType
 Some convenient typedefs. More...
 
typedef OutputImageType OutputType
 
typedef OutputImageType::Pointer OutputImagePointer
 
typedef SlicedData::RegionType OutputImageRegionType
 
- Public Types inherited from mitk::BaseDataSource
typedef BaseDataSource Self
 
typedef itk::ProcessObject Superclass
 
typedef itk::SmartPointer< SelfPointer
 
typedef itk::SmartPointer< const SelfConstPointer
 
typedef BaseData OutputType
 
typedef itk::DataObject::DataObjectIdentifierType DataObjectIdentifierType
 
- Static Protected Member Functions inherited from mitk::ImageSource
static ITK_THREAD_RETURN_TYPE ThreaderCallback (void *arg)
 Static function used as a "callback" by the MultiThreader. More...
 
- Static Protected Member Functions inherited from mitk::BaseDataSource
static Pointer New ()
 

Detailed Description

Class implementing a mitk::ImageToImageFilter for PAUS motion correction.

The filter takes a stack of PA and US images. It then computes the optical flow within the US image and compensates the PA and US images for the flow. Afterwards it returns the stack of PA and US images.

See also
https://docs.opencv.org/3.0-beta/modules/video/doc/motion_analysis_and_object_tracking.html#calcopticalflowfarneback

Definition at line 52 of file mitkPhotoacousticMotionCorrectionFilter.h.

Constructor & Destructor Documentation

◆ PhotoacousticMotionCorrectionFilter()

mitk::PhotoacousticMotionCorrectionFilter::PhotoacousticMotionCorrectionFilter ( )
protected

◆ ~PhotoacousticMotionCorrectionFilter()

mitk::PhotoacousticMotionCorrectionFilter::~PhotoacousticMotionCorrectionFilter ( )
overrideprotected

Member Function Documentation

◆ CheckInput()

void mitk::PhotoacousticMotionCorrectionFilter::CheckInput ( mitk::Image::Pointer  paImage,
mitk::Image::Pointer  usImage 
)
protected

Validate the input images.

The input images have to be non-empty, 3d and have to coincide in the length in each dimension. If any of these conditions are violated, the method will throw an invalid_argument exception.

Parameters
paImageA mitk image
usImageA mitk image
Warning
If the two images are not 3d and do not coincide in the length in each dimension, this method will throw an invalid_argument exception.
Exceptions
invalid_argument

Definition at line 68 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References IMAGE_DIMENSION, and MITK_ERROR.

Referenced by GenerateData().

◆ ComputeFlowMap()

cv::Mat mitk::PhotoacousticMotionCorrectionFilter::ComputeFlowMap ( cv::Mat  flow)
protected

Compute the remapping map from an optical flow.

The optical flow cannot be used directly to compensate an image. Instead we have to generate an appropriate map.

Parameters
flowThe optical flow which is the base for the remapping.
Returns
The remapping map.

Definition at line 163 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageMappingHelper::map().

Referenced by PerformCorrection().

◆ FitMatrixToChar()

cv::Mat mitk::PhotoacousticMotionCorrectionFilter::FitMatrixToChar ( cv::Mat  mat)
protected

Rescale matrix such that the values lie between 0 and 255.

This method rescales the matrix such that its values lie between 0 and 255. In order to do that it uses the maximum and the minimum of the input ultrasonic image.

Warning
This is a specialized method which does not perform the operation in general, but only if the matrix stems from the right ultrasonic image. Therefore, the method should only be called internally.
Parameters
matThe OpenCV matrix to be rescaled
Returns
The rescaled OpenCV matrix

Definition at line 176 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References MAX_MATRIX.

Referenced by PerformCorrection().

◆ GenerateData()

void mitk::PhotoacousticMotionCorrectionFilter::GenerateData ( )
overrideprotected

Apply OpenCV algorithm to compensate motion in a 2d image time series.

This method uses two 3d mitk images. Both will be interpreted as time series of 2d images. GetInput(0) should be a photoacoustic image whereas GetInput(1) should be an ultrasound image. The input will be validated and then converted to OpenCV matrices. In the end the Farneback algorithm will be used to compute the optical flow in consecutive images and compensate for this flow. The Output will be two 3d mitk images of the same dimensions as the input containing the compensated data.

Warning
The input images need to be 3-dimensional (with the same size in each dimension). Otherwise, an invalid_argument exception will be thrown.
Exceptions
invalid_argument

Definition at line 212 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References CheckInput(), mitk::ImageToImageFilter::GetInput(), mitk::ImageSource::GetOutput(), InitializeOutputIfNecessary(), MITK_INFO, and PerformCorrection().

◆ GetBatchSize()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetBatchSize ( ) const
virtual

◆ GetFlags()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetFlags ( ) const
virtual

◆ GetIterations()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetIterations ( ) const
virtual

◆ GetLevels()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetLevels ( ) const
virtual

◆ GetMatrix()

cv::Mat mitk::PhotoacousticMotionCorrectionFilter::GetMatrix ( const mitk::Image::Pointer  input,
unsigned int  i 
)
protected

Extract a 2d slice as OpenCV matrix.

This method extracts slice i from the 3-dimensional image input and converts it to a OpenCV matrix. Internally, the mitkImageToOpenCVImageFilter is used.

Parameters
inputA 3d image from which a slice is extracted as a 2d OpenCV matrix.
iDetermines the slice to be extracted.
Returns
returns a OpenCV matrix containing the 2d slice.

Definition at line 186 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References IMAGE_DIMENSION, and mitk::Image::New().

Referenced by PerformCorrection().

◆ GetPaInput()

mitk::Image::Pointer mitk::PhotoacousticMotionCorrectionFilter::GetPaInput ( )

Wrapper which gets the photoacoustic image out of the correct input.

This method is a wrapper around the GetInput method. It is implemented for convenience such that you do not have to remember which input is for which image.

Returns
The photoacoustic image

Definition at line 47 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageToImageFilter::GetInput().

◆ GetPaOutput()

mitk::Image::Pointer mitk::PhotoacousticMotionCorrectionFilter::GetPaOutput ( )

Wrapper which gets the photoacoustic image out of the correct output.

This method is a wrapper around the GetOutput method. It is implemented for convenience such that you do not have to remember which output is for which image.

Returns
The photoacoustic image

Definition at line 60 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageSource::GetOutput().

◆ GetPolyN()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetPolyN ( ) const
virtual

◆ GetPolySigma()

virtual double mitk::PhotoacousticMotionCorrectionFilter::GetPolySigma ( ) const
virtual

◆ GetPyrScale()

virtual double mitk::PhotoacousticMotionCorrectionFilter::GetPyrScale ( ) const
virtual

◆ GetUsInput()

mitk::Image::Pointer mitk::PhotoacousticMotionCorrectionFilter::GetUsInput ( )

Wrapper which gets the ultrasonic image out of the correct input.

This method is a wrapper around the GetInput method. It is implemented for convenience such that you do not have to remember which input is for which image.

Returns
The ultrasonic image

Definition at line 56 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageToImageFilter::GetInput().

◆ GetUsOutput()

mitk::Image::Pointer mitk::PhotoacousticMotionCorrectionFilter::GetUsOutput ( )

Wrapper which gets the ultrasonic image out of the correct output.

This method is a wrapper around the GetOutput method. It is implemented for convenience such that you do not have to remember which output is for which image.

Returns
The ultrasonic image

Definition at line 64 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageSource::GetOutput().

◆ GetWinSize()

virtual unsigned int mitk::PhotoacousticMotionCorrectionFilter::GetWinSize ( ) const
virtual

◆ InitializeOutput()

void mitk::PhotoacousticMotionCorrectionFilter::InitializeOutput ( mitk::Image::Pointer  input,
mitk::Image::Pointer  output 
)
protected

Copy the image data from the input image to the output image.

This method copys the image data from input to output. This method assumes that the dimensions of the two images match and will not test this.

Parameters
inputA mitk image
outputA mitk image

Definition at line 111 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageAccessorBase::GetData().

Referenced by InitializeOutputIfNecessary().

◆ InitializeOutputIfNecessary()

void mitk::PhotoacousticMotionCorrectionFilter::InitializeOutputIfNecessary ( mitk::Image::Pointer  paInput,
mitk::Image::Pointer  usInput,
mitk::Image::Pointer  paOutput,
mitk::Image::Pointer  usOutput 
)
protected

Assure that the output images have the same dimensions as the input images.

The output images need to have the same dimensions as the input images. This will be checked here. If the dimensions do not match, the output will be reinitialized and the image data from the input images will be copied to the output images (in order to make sure that they have a valid data pointer).

Parameters
paInputPointer to the photoacoustic input image
usInputPointer to the ultrasonic input image
paOutputPointer to the photoacoustic output image
usOutputPointer to the ultrasonic output image

Definition at line 94 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References IMAGE_DIMENSION, and InitializeOutput().

Referenced by GenerateData().

◆ InsertMatrixAsSlice()

void mitk::PhotoacousticMotionCorrectionFilter::InsertMatrixAsSlice ( cv::Mat  mat,
mitk::Image::Pointer  output,
unsigned int  i 
)
protected

Insert a OpenCV matrix as a slice into an image.

This method converts the 2d OpenCV matrix mat into an mitk image using the mitkOpenCVToMitkImageFilter. Afterwards it inserts the image as slice i into the 3d mitk image output.

Parameters
matThe matrix to be inserted as a slice
outputThe 3d image the matrix is inserted into
iThe index of the slice to be replaced.

Definition at line 200 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageAccessorBase::GetData().

Referenced by PerformCorrection().

◆ mitkClassMacro()

mitk::PhotoacousticMotionCorrectionFilter::mitkClassMacro ( PhotoacousticMotionCorrectionFilter  ,
ImageToImageFilter   
)

◆ New()

static Pointer mitk::PhotoacousticMotionCorrectionFilter::New ( )
static

◆ PerformCorrection()

void mitk::PhotoacousticMotionCorrectionFilter::PerformCorrection ( mitk::Image::Pointer  paInput,
mitk::Image::Pointer  usInput,
mitk::Image::Pointer  paOutput,
mitk::Image::Pointer  usOutput 
)
protected

This method performs the actual motion compensation.

This method uses the ultrasonic input image usInput to compute the optical flow in the time series of 2d images. Then it compensates both the usInput and paInput for it and saves the result in usOutput and paOutput respectively. In the background the OpenCV Farneback algorithm is used for the flow determination.

Parameters
paInputThe photoacoustic input image
usInputThe ultrasonic input image
paOutputThe photoacoustic output image
usOutputThe ultrasonic output image

Definition at line 118 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References ComputeFlowMap(), FitMatrixToChar(), GetMatrix(), IMAGE_DIMENSION, and InsertMatrixAsSlice().

Referenced by GenerateData().

◆ SetBatchSize()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetBatchSize ( unsigned int  _arg)
virtual

◆ SetFlags()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetFlags ( unsigned int  _arg)
virtual

◆ SetIterations()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetIterations ( unsigned int  _arg)
virtual

◆ SetLevels()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetLevels ( unsigned int  _arg)
virtual

◆ SetPaInput()

void mitk::PhotoacousticMotionCorrectionFilter::SetPaInput ( mitk::Image::Pointer  input)

Wrapper which sets the photoacoustic image as the correct input.

This method is a wrapper around the SetInput method. It is implemented for convenience such that you do not have to remember which input is for which image.

Parameters
inputThe photoacoustic image

Definition at line 42 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageToImageFilter::SetInput().

◆ SetPolyN()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetPolyN ( unsigned int  _arg)
virtual

◆ SetPolySigma()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetPolySigma ( double  _arg)
virtual

◆ SetPyrScale()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetPyrScale ( double  _arg)
virtual

◆ SetUsInput()

void mitk::PhotoacousticMotionCorrectionFilter::SetUsInput ( mitk::Image::Pointer  input)

Wrapper which sets the ultrasonic image as the correct input.

This method is a wrapper around the SetInput method. It is implemented for convenience such that you do not have to remember which input is for which image.

Parameters
inputThe ultrasonic image

Definition at line 51 of file mitkPhotoacousticMotionCorrectionFilter.cpp.

References mitk::ImageToImageFilter::SetInput().

◆ SetWinSize()

virtual void mitk::PhotoacousticMotionCorrectionFilter::SetWinSize ( unsigned int  _arg)
virtual

The documentation for this class was generated from the following files: