From: David Sarrut Date: Mon, 24 Oct 2011 06:24:08 +0000 (+0200) Subject: First version of clitkLabelImageOverlapMeasure X-Git-Tag: v1.3.0~174^2~39 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=727a01d91215b6c4c808fd92d42ea168d638bf82;p=clitk.git First version of clitkLabelImageOverlapMeasure --- diff --git a/itk/clitkLabelImageOverlapMeasureFilter.h b/itk/clitkLabelImageOverlapMeasureFilter.h new file mode 100644 index 0000000..9b4a458 --- /dev/null +++ b/itk/clitkLabelImageOverlapMeasureFilter.h @@ -0,0 +1,114 @@ +/*========================================================================= + 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 CLITKLABELIMAGEOVERLAPMEASUREFILTER_H +#define CLITKRELATIVEPOSITIONANALYZERFILTER_H + +// clitk +#include "clitkFilterBase.h" +#include "clitkCropLikeImageFilter.h" +#include "clitkSegmentationUtils.h" +// #include "itkLabelOverlapMeasuresImageFilter.h" + +// itk +#include +#include + +namespace clitk { + + //-------------------------------------------------------------------- + /* + Analyze the relative position of a Target (mask image) according + to some Object, in a given Support. Indicate the main important + position of this Target according the Object. + */ + //-------------------------------------------------------------------- + + template + class LabelImageOverlapMeasureFilter: + public virtual FilterBase, + public itk::ImageToImageFilter + { + + public: + /** Standard class typedefs. */ + typedef itk::ImageToImageFilter Superclass; + typedef LabelImageOverlapMeasureFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(LabelImageOverlapMeasureFilter, ImageToImageFilter); + + /** Some convenient typedefs. */ + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::SpacingType SpacingType; + typedef typename ImageType::SizeType SizeType; + typedef typename ImageType::IndexType IndexType; + typedef typename ImageType::PointType PointType; + + /** ImageDimension constants */ + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + FILTERBASE_INIT; + + // Options + itkGetConstMacro(BackgroundValue, PixelType); + itkSetMacro(BackgroundValue, PixelType); + + itkGetConstMacro(Label1, PixelType); + itkSetMacro(Label1, PixelType); + + itkGetConstMacro(Label2, PixelType); + itkSetMacro(Label2, PixelType); + + // I dont want to verify inputs information + virtual void VerifyInputInformation() { } + + protected: + LabelImageOverlapMeasureFilter(); + virtual ~LabelImageOverlapMeasureFilter() {} + + PixelType m_BackgroundValue; + PixelType m_Label1; + PixelType m_Label2; + ImagePointer m_Input1; + ImagePointer m_Input2; + + virtual void GenerateOutputInformation(); + virtual void GenerateInputRequestedRegion(); + virtual void GenerateData(); + + private: + LabelImageOverlapMeasureFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#include "clitkLabelImageOverlapMeasureFilter.txx" + +#endif diff --git a/itk/clitkLabelImageOverlapMeasureFilter.txx b/itk/clitkLabelImageOverlapMeasureFilter.txx new file mode 100644 index 0000000..11c1e42 --- /dev/null +++ b/itk/clitkLabelImageOverlapMeasureFilter.txx @@ -0,0 +1,126 @@ +/*========================================================================= + 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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::LabelImageOverlapMeasureFilter:: +LabelImageOverlapMeasureFilter(): + clitk::FilterBase(), + itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(2); + SetLabel1(1); + SetLabel2(1); + SetBackgroundValue(0); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::LabelImageOverlapMeasureFilter:: +GenerateOutputInformation() +{ + // DD("GenerateOutputInformation"); + //ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + // ImagePointer outputImage = this->GetOutput(0); + // outputImage->SetRegions(outputImage->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::LabelImageOverlapMeasureFilter:: +GenerateInputRequestedRegion() +{ + // DD("GenerateInputRequestedRegion"); + // Call default + itk::ImageToImageFilter::GenerateInputRequestedRegion(); + // Get input pointers and set requested region to common region + ImagePointer input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer input2 = dynamic_cast(itk::ProcessObject::GetInput(1)); + input1->SetRequestedRegion(input1->GetLargestPossibleRegion()); + input2->SetRequestedRegion(input2->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +void +clitk::LabelImageOverlapMeasureFilter:: +GenerateData() +{ + // DD("GenerateData"); + + // Get input pointer + m_Input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); + m_Input2 = dynamic_cast(itk::ProcessObject::GetInput(1)); + static const unsigned int dim = ImageType::ImageDimension; + + // Compute union of bounding boxes + typedef itk::BoundingBox BBType; + typename BBType::Pointer bb1 = BBType::New(); + ComputeBBFromImageRegion(m_Input1, m_Input1->GetLargestPossibleRegion(), bb1); + typename BBType::Pointer bb2 = BBType::New(); + ComputeBBFromImageRegion(m_Input2, m_Input2->GetLargestPossibleRegion(), bb2); + typename BBType::Pointer bbo = BBType::New(); + ComputeBBUnion(bbo, bb1, bb2); + + // Resize like the union + ImagePointer input1 = clitk::ResizeImageLike(m_Input1, bbo, GetBackgroundValue()); + ImagePointer input2 = clitk::ResizeImageLike(m_Input2, bbo, GetBackgroundValue()); + + // Compute overlap image + ImagePointer image_union = clitk::Clone(input1); + ImagePointer image_intersection = clitk::Clone(input1); + clitk::Or(image_union, input2, GetBackgroundValue()); + clitk::And(image_intersection, input2, GetBackgroundValue()); + + writeImage(image_union, "union.mha"); + writeImage(image_intersection, "intersection.mha"); + + // Compute size + typedef itk::LabelStatisticsImageFilter StatFilterType; + typename StatFilterType::Pointer statFilter = StatFilterType::New(); + statFilter->SetInput(image_union); + statFilter->SetLabelInput(image_union); + statFilter->Update(); + int u = statFilter->GetCount(GetLabel1()); + + statFilter->SetInput(image_intersection); + statFilter->SetLabelInput(image_intersection); + statFilter->Update(); + int inter = statFilter->GetCount(GetLabel1()); + + statFilter->SetInput(m_Input1); + statFilter->SetLabelInput(m_Input1); + statFilter->Update(); + int in1 = statFilter->GetCount(GetLabel1()); + + statFilter->SetInput(m_Input2); + statFilter->SetLabelInput(m_Input2); + statFilter->Update(); + int in2 = statFilter->GetCount(GetLabel1()); + + std::cout << in1 << " " << in2 << " " << inter << " " << u << " " << (double)inter/(double)u << std::endl; +} +//-------------------------------------------------------------------- + diff --git a/tools/clitkLabelImageOverlapMeasure.cxx b/tools/clitkLabelImageOverlapMeasure.cxx new file mode 100644 index 0000000..9a7b625 --- /dev/null +++ b/tools/clitkLabelImageOverlapMeasure.cxx @@ -0,0 +1,46 @@ +/*========================================================================= + 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 +===========================================================================**/ + +// clitk +#include "clitkIO.h" +#include "clitkLabelImageOverlapMeasure_ggo.h" +#include "clitkLabelImageOverlapMeasureGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkLabelImageOverlapMeasure, args_info); + CLITK_INIT; + + // Filter + typedef clitk::LabelImageOverlapMeasureGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + filter->SetArgsInfo(args_info); + + try { + filter->Update(); + } catch(std::runtime_error e) { + std::cout << e.what() << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/tools/clitkLabelImageOverlapMeasure.ggo b/tools/clitkLabelImageOverlapMeasure.ggo new file mode 100644 index 0000000..17c28ed --- /dev/null +++ b/tools/clitkLabelImageOverlapMeasure.ggo @@ -0,0 +1,21 @@ +#File clitkLabelImageOverlapMeasure.ggo +package "clitkLabelImageOverlapMeasure" +version "1.0" +purpose "Compute Dice and other coefficients between label images" + +section "General options" +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Display allowed image types" flag off + +section "Input" +option "input1" i "Input mask 1" string yes +option "input2" j "Input mask 2" string yes + +option "label1" l "Label in input1" int no default="1" +option "label2" m "Label in input2" int no default="1" +option "BG" b "Background value" int no default="0" + + + + diff --git a/tools/clitkLabelImageOverlapMeasureGenericFilter.h b/tools/clitkLabelImageOverlapMeasureGenericFilter.h new file mode 100644 index 0000000..a6f8028 --- /dev/null +++ b/tools/clitkLabelImageOverlapMeasureGenericFilter.h @@ -0,0 +1,76 @@ +/*========================================================================= + 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 CLITKLABELIMAGEOVERLAPMEASUREGENERICFILTER_H +#define CLITKLABELIMAGEOVERLAPMEASUREGENERICFILTER_H + +// clitk +#include "clitkImageToImageGenericFilter.h" +#include "clitkLabelImageOverlapMeasureFilter.h" +#include "clitkBoundingBoxUtils.h" +#include "clitkCropLikeImageFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT LabelImageOverlapMeasureGenericFilter: + public ImageToImageGenericFilter > + { + public: + //-------------------------------------------------------------------- + LabelImageOverlapMeasureGenericFilter(); + + //-------------------------------------------------------------------- + typedef ImageToImageGenericFilter > Superclass; + typedef LabelImageOverlapMeasureGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + itkNewMacro(Self); + itkTypeMacro(LabelImageOverlapMeasureGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const ArgsInfoType & a); + template + void SetOptionsFromArgsInfoToFilter(FilterType * f) ; + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + protected: + template void InitializeImageType(); + ArgsInfoType mArgsInfo; + + private: + LabelImageOverlapMeasureGenericFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + };// end class + //-------------------------------------------------------------------- +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkLabelImageOverlapMeasureGenericFilter.txx" +#endif + +#endif // #define CLITKRELATIVEPOSITIONANALYZERGENERICFILTER_H diff --git a/tools/clitkLabelImageOverlapMeasureGenericFilter.txx b/tools/clitkLabelImageOverlapMeasureGenericFilter.txx new file mode 100644 index 0000000..bb1b6eb --- /dev/null +++ b/tools/clitkLabelImageOverlapMeasureGenericFilter.txx @@ -0,0 +1,100 @@ +/*========================================================================= + 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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::LabelImageOverlapMeasureGenericFilter:: +LabelImageOverlapMeasureGenericFilter(): + ImageToImageGenericFilter("LabelImageOverlapMeasure") +{ + // Default values + cmdline_parser_clitkLabelImageOverlapMeasure_init(&mArgsInfo); + //InitializeImageType<2>(); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::LabelImageOverlapMeasureGenericFilter:: +InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::LabelImageOverlapMeasureGenericFilter:: +SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.input1_given) AddInputFilename(mArgsInfo.input1_arg); + if (mArgsInfo.input2_given) AddInputFilename(mArgsInfo.input2_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::LabelImageOverlapMeasureGenericFilter:: +SetOptionsFromArgsInfoToFilter(FilterType * f) +{ + f->SetLabel1(mArgsInfo.label1_arg); + f->SetLabel2(mArgsInfo.label2_arg); +} + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::LabelImageOverlapMeasureGenericFilter:: +UpdateWithInputImageType() +{ + // Reading input + typename ImageType::Pointer input1 = this->template GetInput(0); + typename ImageType::Pointer input2 = this->template GetInput(1); + + // Create filter + typedef clitk::LabelImageOverlapMeasureFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set global Options + filter->SetInput(0, input1); + filter->SetInput(1, input2); + SetOptionsFromArgsInfoToFilter(filter); + + // Go ! + filter->Update(); + + // Write/Save results + // typename ImageType::Pointer output = filter->GetOutput(); + // this->template SetNextOutput(output); +} +//-------------------------------------------------------------------- + +