diff --git a/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.cpp b/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.cpp new file mode 100644 index 0000000000..13d644b49f --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.cpp @@ -0,0 +1,17 @@ +/*=================================================================== + +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 "mitkAbstractOpenCVImageFilter.h" diff --git a/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.h b/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.h new file mode 100644 index 0000000000..38482d9efc --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkAbstractOpenCVImageFilter.h @@ -0,0 +1,56 @@ +/*=================================================================== + +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 mitkCropOpenCVImageFilter_h +#define mitkCropOpenCVImageFilter_h + +#include "mitkOpenCVVideoSupportExports.h" + +#include + +//itk headers +#include + +namespace cv { +class Mat; +} + +namespace mitk { + +/** + * \brief Interface for image filters on OpenCV images. + * Every concrete filter has to implement the pure virual + * mitk::AbstractOpenCVImageFilter::filterImage() method. + * + */ +class MITK_OPENCVVIDEOSUPPORT_EXPORT AbstractOpenCVImageFilter : public itk::Object +{ + +public: + mitkClassMacro(AbstractOpenCVImageFilter, itk::Object); + + /** + * \brief Pure virtual method for filtering an image. + * + * \param image OpenCV image which is supposed to be manipulated. + * \return true if filtering was successfull, false otherwise + */ + virtual bool filterImage( cv::Mat image ) = 0; +}; + +} // namespace mitk + +#endif // mitkCropOpenCVImageFilter_h diff --git a/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp new file mode 100644 index 0000000000..fc5668c5e0 --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp @@ -0,0 +1,34 @@ +/*=================================================================== + +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 "mitkConvertGrayscaleOpenCVImageFilter.h" + +#include "cv.h" + +namespace mitk { + +bool ConvertGrayscaleOpenCVImageFilter::filterImage( cv::Mat image ) +{ + cv::Mat buffer; + + cv::cvtColor(image, buffer, CV_RGB2GRAY, 1); + image.release(); + image = buffer; + + return true; +} + +} // namespace mitk diff --git a/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.h b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.h new file mode 100644 index 0000000000..7eca0ba344 --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.h @@ -0,0 +1,43 @@ +/*=================================================================== + +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 mitkConvertGrayscaleOpenCVImageFilter_h +#define mitkConvertGrayscaleOpenCVImageFilter_h + +#include "mitkAbstractOpenCVImageFilter.h" + +//itk headers +#include "itkObjectFactory.h" + +namespace mitk { + +class MITK_OPENCVVIDEOSUPPORT_EXPORT ConvertGrayscaleOpenCVImageFilter : public AbstractOpenCVImageFilter +{ + +public: + mitkClassMacro(ConvertGrayscaleOpenCVImageFilter, AbstractOpenCVImageFilter); + itkNewMacro(Self); + + /** + * \brief Converts given image to grayscale. + * \return always true + */ + bool filterImage( cv::Mat image ); +}; + +} // namespace mitk + +#endif // mitkConvertGrayscaleOpenCVImageFilter_h diff --git a/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.cpp b/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.cpp new file mode 100644 index 0000000000..aea1a53e59 --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.cpp @@ -0,0 +1,49 @@ +/*=================================================================== + +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 "mitkCropOpenCVImageFilter.h" + +#include "cv.h" + +namespace mitk { + +bool CropOpenCVImageFilter::filterImage( cv::Mat image ) +{ + if (m_CropRegion.width <= 0) + { + MITK_ERROR("AbstractOpenCVImageFilter")("CropOpenCVImageFilter") + << "Cropping cannot be done without setting a non-empty crop region first."; + return false; + } + + cv::Mat buffer = image(m_CropRegion); + image.release(); + image = buffer; + + return true; +} + +void CropOpenCVImageFilter::SetCropRegion( cv::Rect cropRegion ) +{ + m_CropRegion = cropRegion; +} + +cv::Rect CropOpenCVImageFilter::GetCropRegion( ) +{ + return m_CropRegion; +} + +} // namespace mitk diff --git a/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.h b/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.h new file mode 100644 index 0000000000..0bb3d9de45 --- /dev/null +++ b/Modules/OpenCVVideoSupport/Commands/mitkCropOpenCVImageFilter.h @@ -0,0 +1,54 @@ +/*=================================================================== + +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 mitkAbstractOpenCVImageFilter_h +#define mitkAbstractOpenCVImageFilter_h + +#include "mitkAbstractOpenCVImageFilter.h" + +#include "cv.h" + +//itk headers +#include + +namespace mitk { + +class MITK_OPENCVVIDEOSUPPORT_EXPORT CropOpenCVImageFilter : public AbstractOpenCVImageFilter +{ + +public: + mitkClassMacro(CropOpenCVImageFilter, AbstractOpenCVImageFilter); + itkNewMacro(Self); + + /** + * \brief Crops image to rectangle given by mitk::CropOpenCVImageFilter::SetCropRegion. + * \return false if no crop region was set or the crop region width is zero, true otherwise. + */ + bool filterImage( cv::Mat image ); + + void SetCropRegion( cv::Rect cropRegion ); + cv::Rect GetCropRegion( ); + +protected: + /** + * \brief Defines the region which will be cropped from the image. + */ + cv::Rect m_CropRegion; +}; + +} // namespace mitk + +#endif // mitkAbstractOpenCVImageFilter_h diff --git a/Modules/OpenCVVideoSupport/files.cmake b/Modules/OpenCVVideoSupport/files.cmake index fd1990a304..11585fa4e6 100644 --- a/Modules/OpenCVVideoSupport/files.cmake +++ b/Modules/OpenCVVideoSupport/files.cmake @@ -1,14 +1,17 @@ set(CPP_FILES mitkMovieGeneratorOpenCV.cpp mitkUndistortCameraImage.cpp mitkOpenCVVideoSource.cpp mitkOpenCVToMitkImageFilter.cpp mitkImageToOpenCVImageFilter.cpp + Commands/mitkAbstractOpenCVImageFilter.cpp + Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp + Commands/mitkCropOpenCVImageFilter.cpp ) if(MITK_USE_videoInput) set(CPP_FILES ${CPP_FILES} mitkVideoInputSource.cpp ) endif(MITK_USE_videoInput) \ No newline at end of file