From: David Sarrut Date: Mon, 22 Jul 2013 12:56:33 +0000 (+0200) Subject: Updated version with new itk filter X-Git-Tag: v1.4.0~164^2~48 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=27377f74780696955b3174432cf7aeb582a258b8;p=clitk.git Updated version with new itk filter --- diff --git a/itk/clitkLabelImageOverlapMeasureFilter.h b/itk/clitkLabelImageOverlapMeasureFilter.h index 17b7c21..cf0645f 100644 --- a/itk/clitkLabelImageOverlapMeasureFilter.h +++ b/itk/clitkLabelImageOverlapMeasureFilter.h @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + 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 @@ -23,24 +23,24 @@ #include "clitkFilterBase.h" #include "clitkCropLikeImageFilter.h" #include "clitkSegmentationUtils.h" -// #include "itkLabelOverlapMeasuresImageFilter.h" // itk #include #include +#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. + position of this Target according the Object. */ //-------------------------------------------------------------------- - + template class LabelImageOverlapMeasureFilter: public virtual FilterBase, @@ -53,30 +53,30 @@ namespace clitk { 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::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); + //itkSetMacro(BackgroundValue, PixelType); itkGetConstMacro(Label1, PixelType); itkSetMacro(Label1, PixelType); @@ -84,18 +84,28 @@ namespace clitk { itkGetConstMacro(Label2, PixelType); itkSetMacro(Label2, PixelType); + itkSetMacro(VerboseFlag, bool); + itkGetConstMacro(VerboseFlag, bool); + itkBooleanMacro(VerboseFlag); + + itkSetMacro(LongFlag, bool); + itkGetConstMacro(LongFlag, bool); + itkBooleanMacro(LongFlag); + // 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; + bool m_VerboseFlag; + bool m_LongFlag; virtual void GenerateOutputInformation(); virtual void GenerateInputRequestedRegion(); @@ -104,7 +114,7 @@ namespace clitk { private: LabelImageOverlapMeasureFilter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented - + }; // end class //-------------------------------------------------------------------- diff --git a/itk/clitkLabelImageOverlapMeasureFilter.txx b/itk/clitkLabelImageOverlapMeasureFilter.txx index 0375709..e62a1a9 100644 --- a/itk/clitkLabelImageOverlapMeasureFilter.txx +++ b/itk/clitkLabelImageOverlapMeasureFilter.txx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + 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 @@ -26,17 +26,19 @@ LabelImageOverlapMeasureFilter(): this->SetNumberOfRequiredInputs(2); SetLabel1(1); SetLabel2(1); - SetBackgroundValue(0); + m_BackgroundValue = 0; + SetVerboseFlag(false); + SetLongFlag(false); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template -void +void clitk::LabelImageOverlapMeasureFilter:: -GenerateOutputInformation() -{ +GenerateOutputInformation() +{ // DD("GenerateOutputInformation"); //ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); // ImagePointer outputImage = this->GetOutput(0); @@ -47,9 +49,9 @@ GenerateOutputInformation() //-------------------------------------------------------------------- template -void +void clitk::LabelImageOverlapMeasureFilter:: -GenerateInputRequestedRegion() +GenerateInputRequestedRegion() { // Call default itk::ImageToImageFilter::GenerateInputRequestedRegion(); @@ -63,12 +65,10 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- template -void +void clitk::LabelImageOverlapMeasureFilter:: -GenerateData() +GenerateData() { - // DD("GenerateData"); - // Get input pointer m_Input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); m_Input2 = dynamic_cast(itk::ProcessObject::GetInput(1)); @@ -86,60 +86,14 @@ GenerateData() // Resize like the union ImagePointer input1 = clitk::ResizeImageLike(m_Input1, bbo, GetBackgroundValue()); ImagePointer input2 = clitk::ResizeImageLike(m_Input2, bbo, GetBackgroundValue()); - //DD(input1->GetLargestPossibleRegion()); - //DD(input2->GetLargestPossibleRegion()); - - // 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()); - - ImagePointer image_1NotIn2 = clitk::Clone(input1); - clitk::AndNot(image_1NotIn2, input2, GetBackgroundValue()); - - ImagePointer image_2NotIn1 = clitk::Clone(input2); - clitk::AndNot(image_2NotIn1, input1, GetBackgroundValue()); - - //writeImage(image_union, "union.mha"); - //writeImage(image_intersection, "intersection.mha"); - //writeImage(image_1NotIn2, "image_1NotIn2.mha"); - //writeImage(image_2NotIn1, "image_2NotIn1.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()); - - statFilter->SetInput(image_1NotIn2); - statFilter->SetLabelInput(image_1NotIn2); - statFilter->Update(); - int l1notIn2 = statFilter->GetCount(GetLabel1()); - - statFilter->SetInput(image_2NotIn1); - statFilter->SetLabelInput(image_2NotIn1); - statFilter->Update(); - int l2notIn1 = statFilter->GetCount(GetLabel1()); - - double dice = 2.0*(double)inter/(double)(in1+in2); + /* + if (GetVerboseFlag()) { + std::cout << "Resize images to the union of bounding boxes: " + << input1->GetLargestPossibleRegion().GetSize() << std::endl; + } + */ + + /* int width = 6; std::cout << std::setw(width) << in1 << " " << std::setw(width) << in2 << " " @@ -148,6 +102,38 @@ GenerateData() << std::setw(width) << l1notIn2 << " " << std::setw(width) << l2notIn1 << " " << std::setw(width) << dice << " "; //std::endl; + */ + + // Compute overlap, dice + typedef itk::LabelOverlapMeasuresImageFilter FilterType; + typename FilterType::Pointer diceFilter = FilterType::New(); + diceFilter->SetSourceImage(input1); + diceFilter->SetTargetImage(input2); + diceFilter->Update(); + + // Display information + if (!GetLongFlag()) { + if (GetVerboseFlag()) { + std::cout << "Dice : "; + } + std::cout << diceFilter->GetDiceCoefficient() << std::endl; + } + else { // long options + if (GetVerboseFlag()) { + std::cout << "Dice Jaccard Source Target Inter Union SrComp TarComp" << std::endl; + } + typename FilterType::MapType m = diceFilter->GetLabelSetMeasures(); + int width = 6; + std::cout << std::setw(width) << diceFilter->GetDiceCoefficient() << " " + << std::setw(width) << diceFilter->GetJaccardCoefficient() << " " + << std::setw(width) << m[m_Label1].m_Source << " " + << std::setw(width) << m[m_Label2].m_Target << " " + << std::setw(width) << m[m_Label1].m_Intersection << " " + << std::setw(width) << m[m_Label1].m_Union << " " + << std::setw(width) << m[m_Label1].m_SourceComplement << " " + << std::setw(width) << m[m_Label2].m_TargetComplement << " " + << std::endl; + } + } //-------------------------------------------------------------------- -