From: dsarrut Date: Fri, 29 Jan 2010 07:28:33 +0000 (+0000) Subject: - binarize filter X-Git-Tag: v1.2.0~857 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=62e27d7c139840bc8c62eff63792b6b765a10da2;p=clitk.git - binarize filter --- diff --git a/filters/clitkBinarizeImage.ggo b/filters/clitkBinarizeImage.ggo new file mode 100644 index 0000000..becf917 --- /dev/null +++ b/filters/clitkBinarizeImage.ggo @@ -0,0 +1,14 @@ +#File clitkBinarizeImage.ggo +Package "clitkBinarizeImage" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "lower" l "Lower intensity (default=min)" double no +option "upper" u "Upper intensity (default=max)" double no +option "inside" - "Inside value" double no default="1" +option "outside" - "Outside value" double no default="0" diff --git a/filters/clitkBinarizeImageGenericFilter.cxx b/filters/clitkBinarizeImageGenericFilter.cxx new file mode 100644 index 0000000..ca07df1 --- /dev/null +++ b/filters/clitkBinarizeImageGenericFilter.cxx @@ -0,0 +1,15 @@ +#ifndef clitkBinarizeImageGenericFilter_cxx +#define clitkBinarizeImageGenericFilter_cxx + +/* ================================================= + * @file clitkBinarizeImageGenericFilter.cxx + * @author Jef Vandemeulebroucke + * @date 29 june 2009 + * + * @brief + * + ===================================================*/ + +#include "clitkBinarizeImageGenericFilter.h" + +#endif //#define clitkBinarizeImageGenericFilter_cxx diff --git a/filters/clitkBinarizeImageGenericFilter.h b/filters/clitkBinarizeImageGenericFilter.h new file mode 100644 index 0000000..f35bc7a --- /dev/null +++ b/filters/clitkBinarizeImageGenericFilter.h @@ -0,0 +1,89 @@ +/*========================================================================= + + Program: clitk + Module: $RCSfile: clitkBinarizeImageGenericFilter.h,v $ + Language: C++ + Date: $Date: 2010/01/29 07:28:33 $ + Version: $Revision: 1.1 $ + Author : Jef Vandemeulebroucke + David Sarrut (david.sarrut@creatis.insa-lyon.fr) + + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef CLITKBINARIZEIMAGEGENERICFILTER_H +#define CLITKBINARIZEIMAGEGENERICFILTER_H + +// clitk include +#include "clitkIO.h" +#include "clitkCommon.h" +#include "clitkImageToImageGenericFilter.h" + +// itk include +#include "itkBinaryThresholdImageFilter.h" + +// std include +#include + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT BinarizeImageGenericFilter: + public ImageToImageGenericFilter > + { + + public: + + //-------------------------------------------------------------------- + BinarizeImageGenericFilter(); + + //-------------------------------------------------------------------- + typedef BinarizeImageGenericFilter 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(BinarizeImageGenericFilter, 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 "clitkBinarizeImageGenericFilter.txx" +#endif + +#endif // #define clitkBinarizeImageGenericFilter_h diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx new file mode 100644 index 0000000..38f7725 --- /dev/null +++ b/filters/clitkBinarizeImageGenericFilter.txx @@ -0,0 +1,100 @@ +#ifndef clitkBinarizeImageGenericFilter_txx +#define clitkBinarizeImageGenericFilter_txx + +/* ================================================= + * @file clitkBinarizeImageGenericFilter.txx + * @author Jef Vandemeulebroucke + * @date 29 june 2009 + * + * @brief + * + ===================================================*/ + +namespace clitk +{ + + //-------------------------------------------------------------------- + template + BinarizeImageGenericFilter::BinarizeImageGenericFilter(): + ImageToImageGenericFilter("Binarize") { + InitializeImageType<2>(); + InitializeImageType<3>(); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + template + void BinarizeImageGenericFilter::InitializeImageType() { + ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, short); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + void BinarizeImageGenericFilter::SetArgsInfo(const args_info_type & a) { + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + + if (mArgsInfo.input_given) { + SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + SetOutputFilename(mArgsInfo.output_arg); + } + } + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //-------------------------------------------------------------------- + template + template + void + BinarizeImageGenericFilter::UpdateWithInputImageType() + { + + // Reading input + typename InputImageType::Pointer input = this->template GetInput(0); + + // Main filter + typedef typename InputImageType::PixelType PixelType; + typedef itk::Image OutputImageType; + + // Filter + typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; + typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New(); + thresholdFilter->SetInput(input); + if(mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast(mArgsInfo.lower_arg)); + if(mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(mArgsInfo.upper_arg)); + + DD(mArgsInfo.lower_given); + DD(mArgsInfo.upper_given); + DD(mArgsInfo.lower_arg); + DD(mArgsInfo.upper_arg); + + DD(mArgsInfo.inside_arg); + DD(mArgsInfo.outside_arg); + DD(mArgsInfo.inside_given); + DD(mArgsInfo.outside_given); + + thresholdFilter->SetInsideValue(mArgsInfo.inside_arg); + thresholdFilter->SetOutsideValue(mArgsInfo.outside_arg); + + thresholdFilter->Update(); + + // Write/Save results + typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); + this->template SetNextOutput(outputImage); + } + //-------------------------------------------------------------------- + + +}//end clitk + +#endif //#define clitkBinarizeImageGenericFilter_txx