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 m_BackgroundValue = 0;
30 SetVerboseFlag(false);
33 //--------------------------------------------------------------------
36 //--------------------------------------------------------------------
37 template <class ImageType>
39 clitk::LabelImageOverlapMeasureFilter<ImageType>::
40 GenerateOutputInformation()
42 // DD("GenerateOutputInformation");
43 //ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
44 // ImagePointer outputImage = this->GetOutput(0);
45 // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 template <class ImageType>
53 clitk::LabelImageOverlapMeasureFilter<ImageType>::
54 GenerateInputRequestedRegion()
57 itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
58 // Get input pointers and set requested region to common region
59 ImagePointer input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
60 ImagePointer input2 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
61 input1->SetRequestedRegion(input1->GetLargestPossibleRegion());
62 input2->SetRequestedRegion(input2->GetLargestPossibleRegion());
64 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 template <class ImageType>
69 clitk::LabelImageOverlapMeasureFilter<ImageType>::
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());
90 if (GetVerboseFlag()) {
91 std::cout << "Resize images to the union of bounding boxes: "
92 << input1->GetLargestPossibleRegion().GetSize() << std::endl;
98 std::cout << std::setw(width) << in1 << " "
99 << std::setw(width) << in2 << " "
100 << std::setw(width) << inter << " "
101 << std::setw(width) << u << " "
102 << std::setw(width) << l1notIn2 << " "
103 << std::setw(width) << l2notIn1 << " "
104 << std::setw(width) << dice << " "; //std::endl;
107 // Compute overlap, dice
108 typedef itk::LabelOverlapMeasuresImageFilter<ImageType> FilterType;
109 typename FilterType::Pointer diceFilter = FilterType::New();
110 diceFilter->SetSourceImage(input1);
111 diceFilter->SetTargetImage(input2);
112 diceFilter->Update();
114 // Display information
115 if (!GetLongFlag()) {
116 if (GetVerboseFlag()) {
117 std::cout << "Dice : ";
119 std::cout << diceFilter->GetDiceCoefficient() << std::endl;
121 else { // long options
122 if (GetVerboseFlag()) {
123 std::cout << "Dice Jaccard Source Target Inter Union SrComp TarComp" << std::endl;
125 typename FilterType::MapType m = diceFilter->GetLabelSetMeasures();
127 std::cout << std::setw(width) << diceFilter->GetDiceCoefficient() << " "
128 << std::setw(width) << diceFilter->GetJaccardCoefficient() << " "
129 << std::setw(width) << m[m_Label1].m_Source << " "
130 << std::setw(width) << m[m_Label2].m_Target << " "
131 << std::setw(width) << m[m_Label1].m_Intersection << " "
132 << std::setw(width) << m[m_Label1].m_Union << " "
133 << std::setw(width) << m[m_Label1].m_SourceComplement << " "
134 << std::setw(width) << m[m_Label2].m_TargetComplement << " "
139 //--------------------------------------------------------------------