1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 //--------------------------------------------------------------------
20 template <class ImageType>
21 clitk::LabelImageOverlapMeasureFilter<ImageType>::
22 LabelImageOverlapMeasureFilter():
24 itk::ImageToImageFilter<ImageType, ImageType>()
26 this->SetNumberOfRequiredInputs(2);
29 SetBackgroundValue(0);
31 //--------------------------------------------------------------------
34 //--------------------------------------------------------------------
35 template <class ImageType>
37 clitk::LabelImageOverlapMeasureFilter<ImageType>::
38 GenerateOutputInformation()
40 // DD("GenerateOutputInformation");
41 //ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
42 // ImagePointer outputImage = this->GetOutput(0);
43 // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
45 //--------------------------------------------------------------------
48 //--------------------------------------------------------------------
49 template <class ImageType>
51 clitk::LabelImageOverlapMeasureFilter<ImageType>::
52 GenerateInputRequestedRegion()
55 itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
56 // Get input pointers and set requested region to common region
57 ImagePointer input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
58 ImagePointer input2 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
59 input1->SetRequestedRegion(input1->GetLargestPossibleRegion());
60 input2->SetRequestedRegion(input2->GetLargestPossibleRegion());
62 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 template <class ImageType>
67 clitk::LabelImageOverlapMeasureFilter<ImageType>::
70 // DD("GenerateData");
73 m_Input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
74 m_Input2 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
75 static const unsigned int dim = ImageType::ImageDimension;
77 // Compute union of bounding boxes
78 typedef itk::BoundingBox<unsigned long, dim> BBType;
79 typename BBType::Pointer bb1 = BBType::New();
80 ComputeBBFromImageRegion<ImageType>(m_Input1, m_Input1->GetLargestPossibleRegion(), bb1);
81 typename BBType::Pointer bb2 = BBType::New();
82 ComputeBBFromImageRegion<ImageType>(m_Input2, m_Input2->GetLargestPossibleRegion(), bb2);
83 typename BBType::Pointer bbo = BBType::New();
84 ComputeBBUnion<dim>(bbo, bb1, bb2);
86 // Resize like the union
87 ImagePointer input1 = clitk::ResizeImageLike<ImageType>(m_Input1, bbo, GetBackgroundValue());
88 ImagePointer input2 = clitk::ResizeImageLike<ImageType>(m_Input2, bbo, GetBackgroundValue());
89 //DD(input1->GetLargestPossibleRegion());
90 //DD(input2->GetLargestPossibleRegion());
92 // Compute overlap image
93 ImagePointer image_union = clitk::Clone<ImageType>(input1);
94 ImagePointer image_intersection = clitk::Clone<ImageType>(input1);
95 clitk::Or<ImageType>(image_union, input2, GetBackgroundValue());
96 clitk::And<ImageType>(image_intersection, input2, GetBackgroundValue());
98 //writeImage<ImageType>(image_union, "union.mha");
99 //writeImage<ImageType>(image_intersection, "intersection.mha");
102 typedef itk::LabelStatisticsImageFilter<ImageType, ImageType> StatFilterType;
103 typename StatFilterType::Pointer statFilter = StatFilterType::New();
104 statFilter->SetInput(image_union);
105 statFilter->SetLabelInput(image_union);
106 statFilter->Update();
107 int u = statFilter->GetCount(GetLabel1());
109 statFilter->SetInput(image_intersection);
110 statFilter->SetLabelInput(image_intersection);
111 statFilter->Update();
112 int inter = statFilter->GetCount(GetLabel1());
114 statFilter->SetInput(m_Input1);
115 statFilter->SetLabelInput(m_Input1);
116 statFilter->Update();
117 int in1 = statFilter->GetCount(GetLabel1());
119 statFilter->SetInput(m_Input2);
120 statFilter->SetLabelInput(m_Input2);
121 statFilter->Update();
122 int in2 = statFilter->GetCount(GetLabel1());
124 std::cout << in1 << " " << in2 << " " << inter << " " << u << " "
125 << 2.0*(double)inter/(double)(in1+in2) << std::endl;
127 //--------------------------------------------------------------------