diff --git a/Modules/PhotoacousticsAlgorithms/include/mitkPhotoacousticMotionCorrectionFilter.h b/Modules/PhotoacousticsAlgorithms/include/mitkPhotoacousticMotionCorrectionFilter.h new file mode 100644 index 0000000000..056b5c19a4 --- /dev/null +++ b/Modules/PhotoacousticsAlgorithms/include/mitkPhotoacousticMotionCorrectionFilter.h @@ -0,0 +1,80 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef _MITKPHOTOACOUSTICSMOTIONCORRECTIONFILTER_H_ +#define _MITKPHOTOACOUSTICSMOTIONCORRECTIONFILTER_H_ + +#include "mitkImageToImageFilter.h" +#include + +#include "opencv2/imgproc.hpp" +// TODO: Find out why build fails with this option or replace with something else +/* #include "opencv2/opencv.hpp" */ +#include "opencv2/video/tracking.hpp" + +#include "itkOpenCVImageBridge.h" + +#include +#include "mitkImageCast.h" + +namespace mitk +{ + /*! + * \brief Class implementing a mitk::ImageToImageFilter for PAUS motion correction. + * + * TODO: Write down all the parameters needed. + * The filter takes a stack of PA and US images. It then computes the optical flow + * within the US image and compensates the PA images for the flow. Afterwards it + * returns the stack of PA images. + */ + class MITKPHOTOACOUSTICSALGORITHMS_EXPORT PhotoacousticMotionCorrectionFilter : public ImageToImageFilter + { + public: + mitkClassMacro(PhotoacousticMotionCorrectionFilter, ImageToImageFilter); + + itkFactorylessNewMacro(Self); + /* itkCloneMacro(Self); */ + + /* void SetInput(Image::Pointer paImage, Image::Pointer usImage); */ + + // TODO: implement setters and getters for all the parameters + + protected: + PhotoacousticMotionCorrectionFilter(); + + ~PhotoacousticMotionCorrectionFilter() override; + + void GenerateData() override; + + //##Description + //## @brief Time when Header was last initialized + /* itk::TimeStamp m_TimeOfHeaderInitialization; */ + + private: + // InputData + mitk::Image::Pointer m_paImage, m_usImage; + // Parameters + double m_pyr_scale, m_poly_sigma; + int m_levels, m_winsize, m_iterations, m_poly_n, m_flags, m_batch; + /* // Stuff that OpenCV needs */ + cv::Mat m_startImage, m_stopImage, m_flow; + /* cv::UMat m_startImageG, m_StopImageG, m_uflow; */ + // middle step conversion from MITK::image to cv::Mat + // TODO: Note that there is always a float conversion inbetween + itk::Image::Pointer m_itkPaImage, m_itkUsImage; + }; +} +#endif diff --git a/Modules/PhotoacousticsAlgorithms/source/mitkPhotoacousticMotionCorrectionFilter.cpp b/Modules/PhotoacousticsAlgorithms/source/mitkPhotoacousticMotionCorrectionFilter.cpp new file mode 100644 index 0000000000..960c9d3a06 --- /dev/null +++ b/Modules/PhotoacousticsAlgorithms/source/mitkPhotoacousticMotionCorrectionFilter.cpp @@ -0,0 +1,62 @@ +/*=================================================================== + + The Medical Imaging Interaction Toolkit (MITK) + + Copyright (c) German Cancer Research Center, + Division of Medical and Biological Informatics. + All rights reserved. + + This software is distributed WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. + + See LICENSE.txt or http://www.mitk.org for details. + + ===================================================================*/ + +#include "./mitkPhotoacousticMotionCorrectionFilter.h" +#include + +mitk::PhotoacousticMotionCorrectionFilter::PhotoacousticMotionCorrectionFilter() +{ + // Set the defaults for the OpticalFlowFarneback algorithm + // The values are taken directly out of Thomas's US-CV-Based-Optical-Flow-Carotis.ipyn + m_batch = 5; + m_pyr_scale = 0.5; + m_levels = 1; + m_winsize = 40; + m_iterations = 2; + m_poly_n = 7; + m_poly_sigma = 1.5; + m_flags = 0; + + SetNumberOfIndexedInputs(2); + SetNumberOfIndexedOutputs(1); +} + +mitk::PhotoacousticMotionCorrectionFilter::~PhotoacousticMotionCorrectionFilter() +{ +} + +// void mitk::PhotoacousticMotionCorrectionFilter::SetInput(Image::Pointer paImage, +// Image::Pointer usImage) +// { +// m_paImage = paImage; +// m_usImage = usImage; +// } + +void mitk::PhotoacousticMotionCorrectionFilter::GenerateData() +{ + auto input1 = this->GetInput(0); + auto input2 = this->GetInput(1); + + if(input1 && input2) + { + m_paImage = input1; + m_usImage = input2; + + mitk::CastToItkImage(m_paImage, m_itkPaImage); + // TODO: Make sure that only 2d images enter here + m_startImage = itk::OpenCVImageBridge::ITKImageToCVMat< itk::Image >(m_itkPaImage); + } +}