X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkLabelImageOverlapMeasureFilter.txx;fp=itk%2FclitkLabelImageOverlapMeasureFilter.txx;h=11c1e42bca39d9a9aa6662c7e99ac0c08f1051fe;hb=727a01d91215b6c4c808fd92d42ea168d638bf82;hp=0000000000000000000000000000000000000000;hpb=ed35ae164b4aa8dcc5fa4b59683a8cd7de454441;p=clitk.git 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; +} +//-------------------------------------------------------------------- +