From f8fe8f43e398a3e6c5f9d4a3ebc0376d108e9283 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Presles?= Date: Fri, 17 Jan 2014 19:16:49 +0100 Subject: [PATCH] new tool = gaussian blur filtering + improved gradient magnitude tool + added help to clitkImageLaplacian --- tools/CMakeLists.txt | 4 + tools/clitkBlurImage.cxx | 50 ++++++++ tools/clitkBlurImage.ggo | 14 ++ tools/clitkBlurImageGenericFilter.h | 69 ++++++++++ tools/clitkBlurImageGenericFilter.txx | 120 ++++++++++++++++++ tools/clitkImageGradientMagnitude.ggo | 3 +- ...itkImageGradientMagnitudeGenericFilter.txx | 20 ++- tools/clitkImageLaplacian.ggo | 2 +- 8 files changed, 276 insertions(+), 6 deletions(-) create mode 100644 tools/clitkBlurImage.cxx create mode 100644 tools/clitkBlurImage.ggo create mode 100644 tools/clitkBlurImageGenericFilter.h create mode 100644 tools/clitkBlurImageGenericFilter.txx diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 3e7a20b..144fa6f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -320,6 +320,10 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkImageIntensityWindowing clitkCommon ) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageIntensityWindowing) + WRAP_GGO(clitkBlurImage_GGO_C clitkBlurImage.ggo) + ADD_EXECUTABLE(clitkBlurImage clitkBlurImage.cxx ${clitkBlurImage_GGO_C}) + TARGET_LINK_LIBRARIES(clitkBlurImage clitkCommon ) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBlurImage) #========================================================= option(CLITK_USE_ROOT "Build experimental tools using root" OFF) diff --git a/tools/clitkBlurImage.cxx b/tools/clitkBlurImage.cxx new file mode 100644 index 0000000..2aa80d8 --- /dev/null +++ b/tools/clitkBlurImage.cxx @@ -0,0 +1,50 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================**/ + +/* ================================================= + * @file clitkBlurImageGenericFilter.txx + * @author xxx + * @date 29 June 2029 + * + * @brief BlurImage an image + * + ===================================================*/ + +// clitk +#include "clitkBlurImage_ggo.h" +#include "clitkBlurImageGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) +{ + + // Init command line + GGO(clitkBlurImage, args_info); + CLITK_INIT; + + // Filter + typedef clitk::BlurImageGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + filter->SetArgsInfo(args_info); + filter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkBlurImage.ggo b/tools/clitkBlurImage.ggo new file mode 100644 index 0000000..a97becd --- /dev/null +++ b/tools/clitkBlurImage.ggo @@ -0,0 +1,14 @@ +#File clitkBlurImage.ggo +package "clitkBlurImage" +version "1.0" +purpose "Filter the input image with a Gaussian" + +option "config" - "Config file" string optional +option "verbose" v "Verbose" flag off + +option "imagetypes" - "Display allowed image types" flag off + +option "input" i "Input image filename" string required +option "output" o "Output image filename" string required + +option "variance" - "value of the gaussian variance (multiple values=number of image dimension)" double required multiple diff --git a/tools/clitkBlurImageGenericFilter.h b/tools/clitkBlurImageGenericFilter.h new file mode 100644 index 0000000..be79889 --- /dev/null +++ b/tools/clitkBlurImageGenericFilter.h @@ -0,0 +1,69 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================**/ +#ifndef CLITKBlurImageGENERICFILTER_H +#define CLITKBlurImageGENERICFILTER_H +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + +template +class ITK_EXPORT BlurImageGenericFilter: + public ImageToImageGenericFilter > +{ + +public: + + //-------------------------------------------------------------------- + BlurImageGenericFilter(); + + //-------------------------------------------------------------------- + typedef BlurImageGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + // Method for creation through the object factory + // and Run-time type information (and related methods) + itkNewMacro(Self); + itkTypeMacro(BlurImageGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const args_info_type & a); + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + +protected: + template void InitializeImageType(); + args_info_type mArgsInfo; + +}; // end class +//-------------------------------------------------------------------- + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkBlurImageGenericFilter.txx" +#endif + +#endif // #define clitkBlurImageGenericFilter_h diff --git a/tools/clitkBlurImageGenericFilter.txx b/tools/clitkBlurImageGenericFilter.txx new file mode 100644 index 0000000..6868320 --- /dev/null +++ b/tools/clitkBlurImageGenericFilter.txx @@ -0,0 +1,120 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================**/ +#ifndef clitkBlurImageGenericFilter_txx +#define clitkBlurImageGenericFilter_txx + +/* ================================================= + * @file clitkBlurImageGenericFilter.txx + * @author Jef Vandemeulebroucke + * @date 29 june 2009 + * + * @brief + * + ===================================================*/ + +// itk include +#include "itkDiscreteGaussianImageFilter.h" +#include + +namespace clitk +{ + +//-------------------------------------------------------------------- +template +BlurImageGenericFilter::BlurImageGenericFilter(): + ImageToImageGenericFilter("BlurImage") +{ + InitializeImageType<2>(); + InitializeImageType<3>(); + //InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void BlurImageGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void BlurImageGenericFilter::SetArgsInfo(const args_info_type & a) +{ + mArgsInfo=a; + this->SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + + if (mArgsInfo.input_given) { + this->SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + this->SetOutputFilename(mArgsInfo.output_arg); + } +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void +BlurImageGenericFilter::UpdateWithInputImageType() +{ + const unsigned int dim = InputImageType::ImageDimension; + double varianceArray[dim]; + + //std::cout<<"mArgsInfo.variance_given"<template GetInput(0); + + // Main filter + typedef typename InputImageType::PixelType PixelType; + typedef itk::Image OutputImageType; + + // Filter + typedef itk::DiscreteGaussianImageFilter DiscreteGaussianImageFilterType; + typename DiscreteGaussianImageFilterType::Pointer gaussianFilter=DiscreteGaussianImageFilterType::New(); + gaussianFilter->SetInput(input); + gaussianFilter->SetVariance(varianceArray); + gaussianFilter->Update(); + + // Write/Save results + this->template SetNextOutput(gaussianFilter->GetOutput()); +} +//-------------------------------------------------------------------- + + +}//end clitk + +#endif //#define clitkBlurImageGenericFilter_txx diff --git a/tools/clitkImageGradientMagnitude.ggo b/tools/clitkImageGradientMagnitude.ggo index 4677ac3..3863262 100644 --- a/tools/clitkImageGradientMagnitude.ggo +++ b/tools/clitkImageGradientMagnitude.ggo @@ -1,7 +1,7 @@ #File clitkImageGradientMagnitude.ggo package "clitkImageGradientMagnitude" version "1.0" -purpose "" +purpose "Compute the gradient magnitude of the input image" option "config" - "Config file" string optional option "verbose" v "Verbose" flag off @@ -12,3 +12,4 @@ option "input" i "Input image filename" string required option "mask" m "Mask input image filename" string optional option "output" o "Output image filename" string required option "normalize" n "Normalize the output image between 0 and 1" flag off +option "gaussian_filter" g "Gaussian filtering" flag off diff --git a/tools/clitkImageGradientMagnitudeGenericFilter.txx b/tools/clitkImageGradientMagnitudeGenericFilter.txx index 95ac742..19bf823 100644 --- a/tools/clitkImageGradientMagnitudeGenericFilter.txx +++ b/tools/clitkImageGradientMagnitudeGenericFilter.txx @@ -29,6 +29,7 @@ // itk include #include "itkGradientMagnitudeImageFilter.h" +#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h" #include "itkLabelStatisticsImageFilter.h" #include "itkMaskImageFilter.h" #include "itkMaskNegatedImageFilter.h" @@ -127,13 +128,24 @@ namespace clitk IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion()); // Filter + typename OutputImageType::Pointer outputGradientFilter; + if (mArgsInfo.gaussian_filter_flag == 0) { typedef itk::GradientMagnitudeImageFilter GradientMagnitudeImageFilterType; typename GradientMagnitudeImageFilterType::Pointer gradientFilter=GradientMagnitudeImageFilterType::New(); gradientFilter->SetInput(input); gradientFilter->Update(); + outputGradientFilter = gradientFilter->GetOutput(); + } + else { + typedef itk::GradientMagnitudeRecursiveGaussianImageFilter GradientMagnitudeImageFilterType; + typename GradientMagnitudeImageFilterType::Pointer gradientFilter=GradientMagnitudeImageFilterType::New(); + gradientFilter->SetInput(input); + gradientFilter->Update(); + outputGradientFilter = gradientFilter->GetOutput(); + } // Set iterator typedef itk::ImageRegionIterator IteratorType; - IteratorType it(gradientFilter->GetOutput(), gradientFilter->GetOutput()->GetLargestPossibleRegion()); + IteratorType it(outputGradientFilter, outputGradientFilter->GetLargestPossibleRegion()); // Set mask iterator typedef itk::ImageRegionIterator IteratorMaskType; @@ -141,12 +153,12 @@ namespace clitk //typedef itk::MinimumMaximumImageCalculator ImageCalculatorFilterType; //typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New(); - //imageCalculatorFilter->SetImage(gradientFilter->GetOutput()); + //imageCalculatorFilter->SetImage(outputGradientFilter); //imageCalculatorFilter->Compute(); typedef itk::LabelStatisticsImageFilter< OutputImageType, MaskImageType > LabelStatisticsImageFilterType; typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New(); labelStatisticsImageFilter->SetLabelInput( mask ); - labelStatisticsImageFilter->SetInput(gradientFilter->GetOutput()); + labelStatisticsImageFilter->SetInput(outputGradientFilter); labelStatisticsImageFilter->Update(); //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl; @@ -172,7 +184,7 @@ namespace clitk ++itm; } - //typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput(); + //typename OutputImageType::Pointer outputImage = outputGradientFilter; this->template SetNextOutput(outputImage); } //-------------------------------------------------------------------- diff --git a/tools/clitkImageLaplacian.ggo b/tools/clitkImageLaplacian.ggo index f97ef9b..4ba1afd 100644 --- a/tools/clitkImageLaplacian.ggo +++ b/tools/clitkImageLaplacian.ggo @@ -1,7 +1,7 @@ #File clitkImageLaplacian.ggo package "clitkImageLaplacian" version "1.0" -purpose "" +purpose "Compute the laplacian of the input image" option "config" - "Config file" string optional option "verbose" v "Verbose" flag off -- 2.47.1