diff --git a/Modules/ToFProcessing/Testing/CMakeLists.txt b/Modules/ToFProcessing/Testing/CMakeLists.txt index d45daf111d..7d5de41cfc 100644 --- a/Modules/ToFProcessing/Testing/CMakeLists.txt +++ b/Modules/ToFProcessing/Testing/CMakeLists.txt @@ -1 +1,10 @@ -MITK_CREATE_MODULE_TESTS() \ No newline at end of file +MITK_CREATE_MODULE_TESTS() + +IF(BUILD_TESTING AND MODULE_IS_ENABLED) + mitkAddCustomModuleTest("mitkToFImageDownsamplingFilterTest" #name of the test + "mitkToFImageDownsamplingFilterTest" #call the corresponding test + "PMDCamCube2_MF0_IT0_20Images_DistanceImage.pic") #input parameter(s) + mitkAddCustomModuleTest("mitkToFImageDownsamplingFilterTest" #name of the test + "mitkToFImageDownsamplingFilterTest" #call the corresponding test + "PMDCamCube2_MF0_IT0_1Images_DistanceImage.pic") #input parameter(s) +ENDIF(BUILD_TESTING AND MODULE_IS_ENABLED) \ No newline at end of file diff --git a/Modules/ToFProcessing/Testing/files.cmake b/Modules/ToFProcessing/Testing/files.cmake index 39bc777b86..6d2c5050b3 100644 --- a/Modules/ToFProcessing/Testing/files.cmake +++ b/Modules/ToFProcessing/Testing/files.cmake @@ -1,7 +1,8 @@ SET(MODULE_TESTS mitkToFDistanceImageToPointSetFilterTest.cpp mitkToFDistanceImageToSurfaceFilterTest.cpp mitkToFCompositeFilterTest.cpp mitkToFVisualizationFilterTest.cpp mitkToFProcessingCommonTest.cpp + mitkToFImageDownsamplingFilterTest.cpp ) diff --git a/Modules/ToFProcessing/Testing/mitkToFImageDownsamplingFilterTest.cpp b/Modules/ToFProcessing/Testing/mitkToFImageDownsamplingFilterTest.cpp new file mode 100644 index 0000000000..9e1b677d0f --- /dev/null +++ b/Modules/ToFProcessing/Testing/mitkToFImageDownsamplingFilterTest.cpp @@ -0,0 +1,96 @@ + +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ +Version: $Revision: 7837 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +//mitk includes +#include +#include +#include +#include +#include "mitkToFImageDownsamplingFilter.h" + +// creator class that provides pre-configured ToFCameraDevices + + + +int mitkToFImageDownsamplingFilterTest(int argc , char* argv[]) +{ + //Defining constants + const int XDIM = 127; + const int YDIM = 96; + const int ZDIM = 19; + + // always start with this + + MITK_TEST_BEGIN("mitkToFImageDownSamplingFilterFilter"); + + // create a new instance of filter and new image + mitk::ToFImageDownsamplingFilter::Pointer testDownSampler = mitk::ToFImageDownsamplingFilter::New(); + + // make sure new filter ins't null + MITK_TEST_CONDITION_REQUIRED(testDownSampler.IsNotNull(), "Testing instantiation!"); + + + // Load ToF image + MITK_INFO<<"Loading test image file: " << argv[1] << "\n"; // update with proper path and figure out how iti s passed from the test driver + mitk::PicFileReader::Pointer reader = mitk::PicFileReader::New(); + + std::string filename = MITK_TOF_DATA_DIR; + filename.append("/"); + filename.append(argv[1]); + reader->SetFileName(filename); + reader->Update(); + mitk::Image::Pointer image = reader->GetOutput(); + + MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(), "Testing image reading"); + MITK_INFO << "Original image dimensions " << image->GetDimension (0)<<" " << image->GetDimension(1)<< " " << image->GetDimension(2) ; + + //call filter + testDownSampler->SetInput(image); + testDownSampler->SetResampledX(XDIM); + testDownSampler->SetResampledY(YDIM); + testDownSampler->SetResampledZ(ZDIM); + + if(image->GetDimension(0) >= XDIM && image->GetDimension(1)>=YDIM && image->GetDimension(2)>=ZDIM && + (image->GetDimension()==2 || image->GetDimension()==3)) + { + testDownSampler->Update(); + mitk::Image::Pointer resultImage = testDownSampler->GetOutput(); + MITK_TEST_CONDITION_REQUIRED(resultImage->GetDimension(0) == XDIM && resultImage->GetDimension(1)==YDIM &&resultImage->GetDimension(2)==ZDIM, "Test result image dimensions with 3D image"); + MITK_INFO << "new image dimensions " << resultImage->GetDimension (0)<<" " << resultImage->GetDimension(1)<<" " << resultImage->GetDimension(2) ; + } + else + { + MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject); + testDownSampler->Update(); + MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject); + } + + + + // Mean for debugging purposes if you want to write the resutling image to a file + //mitk::PicFileWriter::Pointer writer = mitk::PicFileWriter::New(); + //writer->SetInputImage( resultImage); + //writer->SetFileName( "tofResult1.pic" ); + + //writer->Update(); + + + // always end with this! + MITK_TEST_END(); +} + diff --git a/Modules/ToFProcessing/files.cmake b/Modules/ToFProcessing/files.cmake index 7b47264987..23b971defc 100644 --- a/Modules/ToFProcessing/files.cmake +++ b/Modules/ToFProcessing/files.cmake @@ -1,9 +1,10 @@ SET(CPP_FILES mitkToFCompositeFilter.cpp mitkToFDistanceImageToPointSetFilter.cpp mitkToFDistanceImageToSurfaceFilter.cpp + mitkToFImageDownsamplingFilter.cpp mitkToFProcessingCommon.cpp mitkToFSurfaceVtkMapper3D.cpp - mitkToFVisualizationFilter.cpp mitkToFTestingCommon.cpp + mitkToFVisualizationFilter.cpp ) diff --git a/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.cpp b/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.cpp new file mode 100644 index 0000000000..49a4b97c11 --- /dev/null +++ b/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.cpp @@ -0,0 +1,132 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkToFImageDownsamplingFilter.h" +#include +#include +#include +#include +#include +#include +#include + +mitk::ToFImageDownsamplingFilter::ToFImageDownsamplingFilter(): +m_ResampledX(100), m_ResampledY(100),m_ResampledZ(1) +{ +} + +mitk::ToFImageDownsamplingFilter::~ToFImageDownsamplingFilter() +{ +} + + + + + +void mitk::ToFImageDownsamplingFilter::GenerateData() +{ + // set input image + + mitk::Image::ConstPointer inputImage = this->GetInput(0) ; + if ( (inputImage->GetDimension() > 3) || (inputImage->GetDimension() < 2) ) + { + MITK_ERROR << "mitk::TofImageDownsamplingFilter:GenerateData works only with 2D and 3D images, sorry." << std::endl; + itkExceptionMacro("mitk::TofImageDownsamplingFilter:GenerateData works only with 2D and 3D images, sorry."); + return; + } + + if ( (inputImage->GetDimension(0)GetDimension(1)GetDimension(2)GetDimension()) + { + case 2: + { + AccessFixedDimensionByItk( inputImage.GetPointer(), ItkImageResampling, 2 ); break; + } + case 3: + { + AccessFixedDimensionByItk( inputImage.GetPointer(), ItkImageResampling, 3 ); break; + } + + default: break; + } + + +} + +template +void mitk::ToFImageDownsamplingFilter::ItkImageResampling( itk::Image* itkImage ) +{ + // declare typdef for itk image from input mitk image + typedef itk::Image< TPixel, VImageDimension > ItkImageType; + + //declare itk filter related typedefs (transform type, interpolater, and size type) + typedef itk::ResampleImageFilter ResamplerFilterType; + typedef itk::IdentityTransform TransformType; + typedef itk::NearestNeighborInterpolateImageFunction InterpolatorType; + typedef ItkImageType::SizeType::SizeValueType SizeValueType; + + //instantiate filter related parameters + ResamplerFilterType::Pointer resampler = ResamplerFilterType::New(); + TransformType::Pointer transform = TransformType::New(); + InterpolatorType::Pointer interpolator = InterpolatorType::New(); + + // establish size for downsampled image ( the result of this filter) + ItkImageType::SizeType inputSize = itkImage->GetLargestPossibleRegion().GetSize(); + ItkImageType::SizeType size; + + size[0] = static_cast< SizeValueType >( m_ResampledX ); + size[1] = static_cast< SizeValueType >( m_ResampledY ); + size[2] = static_cast< SizeValueType >( m_ResampledZ ); + + //establish spacing for new downsampled image ( resulting image) + const ItkImageType::SpacingType& inputSpacing = itkImage->GetSpacing(); + ItkImageType::SpacingType spacing; + + spacing[0] = inputSpacing[0] * ( inputSize[0]/ m_ResampledX ); + spacing[1] = inputSpacing[1] * ( inputSize[1]/ m_ResampledY ); + spacing[2] = inputSpacing[2] * ( inputSize[2]/ m_ResampledZ ); + + // set filter parameters and update + transform->SetIdentity(); + resampler->SetTransform(transform); + resampler->SetInterpolator(interpolator); + resampler->SetOutputSpacing(spacing); + resampler->SetOutputOrigin(itkImage->GetOrigin()); + resampler->SetSize(size); + resampler->SetInput(itkImage); + resampler->UpdateLargestPossibleRegion(); + + // Create mitk container for resulting image + mitk::Image::Pointer resultImage = ImageToImageFilter::GetOutput(); + + // Cast itk image to mitk image + mitk::CastToMitkImage(resampler->GetOutput(), resultImage); +} \ No newline at end of file diff --git a/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.h b/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.h new file mode 100644 index 0000000000..81b9bc5da8 --- /dev/null +++ b/Modules/ToFProcessing/mitkToFImageDownsamplingFilter.h @@ -0,0 +1,87 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __mitkToFImageDownsamplingFilter_h +#define __mitkToFImageDownsamplingFilter_h + +//MITK includes +#include +#include "mitkImageToImageFilter.h" +#include "mitkToFProcessingExports.h" +// ITK includes +#include "itkImage.h" + +namespace mitk +{ + /** + * @brief Reduces the resolution of a ToF distance image. Although it is meant to be used for ToF distance images, it should work + * for any 2D or 3D images. The dimensions (in pixels) of the desired image are taken as input parameters, and an image with these + * specified dimensions is created. + * + * @ingroup SurfaceFilters + * @ingroup ToFProcessing + */ + + class mitkToFProcessing_EXPORT ToFImageDownsamplingFilter : public ImageToImageFilter + { + public: + mitkClassMacro(ToFImageDownsamplingFilter, ImageToImageFilter); + itkNewMacro(Self); + + itkSetMacro(ResampledX,double); + itkGetMacro(ResampledX,double); + + itkSetMacro(ResampledY,double); + itkGetMacro(ResampledY,double); + + itkSetMacro(ResampledZ,double); + itkGetMacro(ResampledZ,double); + + + protected: + /*! + \brief Standard constructor + */ + ToFImageDownsamplingFilter(); + + /*! + \brief Standard destructor + */ + ~ToFImageDownsamplingFilter(); + + /*! + \brief Method generating the output of this filter. Called in the updated process of the pipeline. + This method calls the AccessFixedDimensionByItk class with the ItkImageResampling function below + */ + virtual void GenerateData(); + + /*! + \brief Templated method for ITK image type which performs the resampling with an itk filter. + \param itkImage is the input to the filter converted to ITK format + \param TPixel is a pixel type such as float or char or double + \param VImageDimension is the image dimension (2D or 3D) + */ + template + void ItkImageResampling( itk::Image* itkImage ); + + double m_ResampledX;///< length of x dimension of output image in pixels + double m_ResampledY;///< length of y dimension of output image in pixels + double m_ResampledZ;///< length of z dimension of output image in pixels (if 2D, default is set to 1) + + }; +}// end namespace mitk +#endif \ No newline at end of file