From: BenoƮt Presles Date: Thu, 5 Sep 2013 17:07:55 +0000 (+0200) Subject: Median Filter + some bug corrections in Resample Image Filter X-Git-Tag: v1.4.0~162^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0b69855f265de2c9f13f717ec67265df8b1cbd96;p=clitk.git Median Filter + some bug corrections in Resample Image Filter --- diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 1ba42ec..7b389c2 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -70,6 +70,6 @@ ELSE(ITK_VERSION_MAJOR LESS "4") SET(CLITK_USE_SYSTEM_GDCM TRUE) ENDIF() ENDIF(ITK_VERSION_MAJOR LESS "4") - +SET(CLITK_USE_SYSTEM_GDCM FALSE) #DD(CLITK_USE_SYSTEM_GDCM) diff --git a/itk/clitkResampleImageWithOptionsFilter.h b/itk/clitkResampleImageWithOptionsFilter.h index b526207..4b6b409 100644 --- a/itk/clitkResampleImageWithOptionsFilter.h +++ b/itk/clitkResampleImageWithOptionsFilter.h @@ -60,6 +60,8 @@ namespace clitk { typedef typename OutputImageType::PixelType OutputImagePixelType; typedef typename OutputImageType::SpacingType OutputImageSpacingType; typedef typename OutputImageType::SizeType OutputImageSizeType; + typedef typename OutputImageType::PointType OutputImageOriginType; + typedef typename OutputImageType::DirectionType OutputImageDirectionType; typedef itk::AffineTransform TransformType; typedef typename InputImageType::SpacingType GaussianSigmaType; @@ -96,6 +98,10 @@ namespace clitk { itkGetMacro(OutputSpacing, OutputImageSpacingType); itkSetMacro(OutputSize, OutputImageSizeType); itkGetMacro(OutputSize, OutputImageSizeType); + itkSetMacro(OutputOrigin, OutputImageOriginType); + itkGetMacro(OutputOrigin, OutputImageOriginType); + itkSetMacro(OutputDirection, OutputImageDirectionType); + itkGetMacro(OutputDirection, OutputImageDirectionType); itkGetMacro(InterpolationType, InterpolationTypeEnumeration); itkSetMacro(InterpolationType, InterpolationTypeEnumeration); itkGetMacro(GaussianFilteringEnabled, bool); @@ -124,7 +130,9 @@ namespace clitk { int m_BSplineOrder; int m_BLUTSamplingFactor; OutputImageSizeType m_OutputSize; - OutputImageSpacingType m_OutputSpacing; + OutputImageSpacingType m_OutputSpacing; + OutputImageOriginType m_OutputOrigin; + OutputImageDirectionType m_OutputDirection; typename TransformType::Pointer m_Transform; GaussianSigmaType m_GaussianSigma; OutputImagePixelType m_DefaultPixelValue; diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index ddaa8a0..35eae54 100644 --- a/itk/clitkResampleImageWithOptionsFilter.txx +++ b/itk/clitkResampleImageWithOptionsFilter.txx @@ -54,6 +54,8 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilterSetTransform(m_Transform); filter->SetSize(m_OutputSize); filter->SetOutputSpacing(m_OutputSpacing); - filter->SetOutputOrigin(origin); + filter->SetOutputOrigin(m_OutputOrigin); filter->SetDefaultPixelValue(m_DefaultPixelValue); filter->SetNumberOfThreads(this->GetNumberOfThreads()); - filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) + filter->SetOutputDirection(m_OutputDirection); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) // Select interpolator switch (m_InterpolationType) { diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 6d70fc3..7ab7971 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -157,10 +157,10 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkFooImage clitkCommon ) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkFooImage) - #WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo) - #ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C}) - #TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkMedianImageFilterLib clitkCommon) - #SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMedianImageFilter) + WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo) + ADD_EXECUTABLE(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C}) + TARGET_LINK_LIBRARIES(clitkMedianImageFilter clitkMedianImageFilterLib clitkCommon) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMedianImageFilter) ADD_EXECUTABLE(clitkResampleImage clitkResampleImage.cxx) TARGET_LINK_LIBRARIES(clitkResampleImage clitkResampleImageLib clitkCommon) diff --git a/tools/clitkMedianImageGenericFilter.h b/tools/clitkMedianImageGenericFilter.h index 58fac09..f6dc478 100644 --- a/tools/clitkMedianImageGenericFilter.h +++ b/tools/clitkMedianImageGenericFilter.h @@ -61,10 +61,11 @@ namespace clitk public: //-------------------------------------------------------------------- - MedianImageGenericFilter(); + MedianImageGenericFilter(); //-------------------------------------------------------------------- - typedef MedianImageGenericFilter Self; + typedef MedianImageGenericFilter Self; + typedef ImageToImageGenericFilter > Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; @@ -81,15 +82,15 @@ namespace clitk // Main function called each time the filter is updated template void UpdateWithInputImageType(); - - - protected: template void InitializeImageType(); - args_info_type mArgsInfo; - + + private: + MedianImageGenericFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + }; // end class //-------------------------------------------------------------------- diff --git a/tools/clitkMedianImageGenericFilter.txx b/tools/clitkMedianImageGenericFilter.txx index 7e4a426..75567c4 100644 --- a/tools/clitkMedianImageGenericFilter.txx +++ b/tools/clitkMedianImageGenericFilter.txx @@ -89,28 +89,26 @@ MedianImageGenericFilter::UpdateWithInputImageType() // typedef itk::Image OutputImageType; - // Main filter - typedef itk::Image OutputImageType; - typename InputImageType::SizeType indexRadius; - // Filter - typedef itk::MedianImageFilter MedianImageFilterType; - typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New(); - thresholdFilter->SetInput(input); - - for (unsigned i = 0; i < InputImageType::ImageDimension; ++i) - indexRadius[i]=mArgsInfo.radius_arg[i]; - - // indexRadius[0] = 1; - // indexRadius[1] = 1; - - thresholdFilter->SetRadius( indexRadius ); - - typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); - thresholdFilter->Update(); + typedef itk::MedianImageFilter MedianImageFilterType; + typename MedianImageFilterType::Pointer medianFilter=MedianImageFilterType::New(); + typename MedianImageFilterType::InputSizeType radius; + radius.Fill(1); + medianFilter->SetInput(input); + + if(mArgsInfo.radius_given) { + for (unsigned i = 0; i < InputImageType::ImageDimension; ++i) + radius[i]=mArgsInfo.radius_arg[i]; + } + // + std::cout<<"radius median filter= "<SetRadius( radius ); + medianFilter->Update(); // Write/Save results - this->template SetNextOutput(outputImage); + typename InputImageType::Pointer outputImage = medianFilter->GetOutput(); + this->template SetNextOutput(outputImage); } //-------------------------------------------------------------------- diff --git a/tools/clitkResampleImageGenericFilter.txx b/tools/clitkResampleImageGenericFilter.txx index 3448227..b42d183 100644 --- a/tools/clitkResampleImageGenericFilter.txx +++ b/tools/clitkResampleImageGenericFilter.txx @@ -49,6 +49,8 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType() static const unsigned int dim = OutputImageType::ImageDimension; typename OutputImageType::SpacingType spacing; typename OutputImageType::SizeType size; + typename OutputImageType::PointType origin; + typename OutputImageType::DirectionType direction; if (mArgsInfo.like_given) { itk::ImageIOBase::Pointer header = clitk::readImageHeader(mArgsInfo.like_arg); @@ -56,9 +58,17 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType() for(unsigned int i=0; iGetSpacing(i); size[i] = header->GetDimensions(i); + origin[i] = header->GetOrigin(i); + } + for(unsigned int i=0; iGetDirection(i)[j]; + } } filter->SetOutputSpacing(spacing); filter->SetOutputSize(size); + filter->SetOutputOrigin(origin); + filter->SetOutputDirection(direction); } else { std::cerr << "*** Warning : I could not read '" << mArgsInfo.like_arg << "' ***" << std::endl; @@ -91,6 +101,17 @@ clitk::ResampleImageGenericFilter::UpdateWithInputImageType() size[i] = mArgsInfo.size_arg[i]; filter->SetOutputSize(size); } + itk::ImageIOBase::Pointer header = clitk::readImageHeader(mArgsInfo.input_arg); + for(unsigned int i=0; iGetOrigin(i); + } + for(unsigned int i=0; iGetDirection(i)[j]; + } + } + filter->SetOutputOrigin(origin); + filter->SetOutputDirection(direction); } // Set temporal dimension