/*========================================================================= 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() { // 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()); //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); int width = 6; std::cout << std::setw(width) << in1 << " " << std::setw(width) << in2 << " " << std::setw(width) << inter << " " << std::setw(width) << u << " " << std::setw(width) << l1notIn2 << " " << std::setw(width) << l2notIn1 << " " << std::setw(width) << dice << " "; //std::endl; } //--------------------------------------------------------------------