diff --git a/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp b/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp index 015bbf4581..7c209d2d4a 100644 --- a/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp +++ b/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp @@ -1,135 +1,137 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // mitk includes #include "mitkCompareImageDataFilter.h" #include "mitkImageAccessByItk.h" #include "mitkITKImageImport.h" #include "mitkImageCaster.h" #include "mitkMultiComponentImageDataComparisonFilter.h" // itk includes #include mitk::CompareImageDataFilter::CompareImageDataFilter() { this->SetNumberOfRequiredInputs(2); this->ResetCompareResultsToInitial(); } void mitk::CompareImageDataFilter::ResetCompareResultsToInitial() { m_CompareDetails.m_MaximumDifference = 0.0f; m_CompareDetails.m_MinimumDifference = itk::NumericTraits< double >::max(); m_CompareDetails.m_MeanDifference = 0.0f; m_CompareDetails.m_TotalDifference = 0.0f; m_CompareDetails.m_PixelsWithDifference = 0; m_CompareDetails.m_FilterCompleted = false; m_CompareDetails.m_ExceptionMessage = ""; } void mitk::CompareImageDataFilter::GenerateData() { // check inputs const mitk::Image* input1 = this->GetInput(0); const mitk::Image* input2 = this->GetInput(1); // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data // so no further image type comparison is performed! // CAVE: If the images differ in a parameter other then the image data, the filter may fail!! // check what number of components the inputs have if(input1->GetPixelType().GetNumberOfComponents() == 1 && input2->GetPixelType().GetNumberOfComponents() == 1) { AccessByItk_1( input1, EstimateValueDifference, input2); } else if(input1->GetPixelType().GetNumberOfComponents() > 1 && input2->GetPixelType().GetNumberOfComponents() > 1 ) { this->ResetCompareResultsToInitial(); MultiComponentImageDataComparisonFilter::Pointer mcComparator = MultiComponentImageDataComparisonFilter::New(); mcComparator->SetTestImage(input1); mcComparator->SetValidImage(input2); mcComparator->SetCompareFilterResult( &m_CompareDetails); mcComparator->Update(); + + m_CompareResult = mcComparator->GetResult(); } } bool mitk::CompareImageDataFilter::GetResult(size_t threshold) { if (! m_CompareResult) { return false; } if( m_CompareDetails.m_PixelsWithDifference > threshold ) { return false; } return true; } template< typename TPixel, unsigned int VImageDimension> void mitk::CompareImageDataFilter::EstimateValueDifference(itk::Image< TPixel, VImageDimension>* itkImage1, const mitk::Image* referenceImage) { typedef itk::Image< TPixel, VImageDimension> InputImageType; typedef itk::Image< double, VImageDimension > OutputImageType; typename InputImageType::Pointer itk_reference = InputImageType::New(); mitk::CastToItkImage( referenceImage, itk_reference ); typedef itk::Testing::ComparisonImageFilter< InputImageType, OutputImageType > CompareFilterType; typename CompareFilterType::Pointer compare_filter = CompareFilterType::New(); compare_filter->SetTestInput( itkImage1 ); compare_filter->SetValidInput( itk_reference ); try { compare_filter->Update(); } catch( const itk::ExceptionObject& e) { m_CompareDetails.m_FilterCompleted = false; m_CompareDetails.m_ExceptionMessage = e.what(); MITK_WARN << e.what(); m_CompareResult = false; return; } // the filter has completed the calculation m_CompareResult = true; m_CompareDetails.m_FilterCompleted = true; m_CompareDetails.m_MaximumDifference = compare_filter->GetMaximumDifference(); m_CompareDetails.m_MinimumDifference = compare_filter->GetMinimumDifference(); m_CompareDetails.m_MeanDifference = compare_filter->GetMeanDifference(); m_CompareDetails.m_TotalDifference = compare_filter->GetTotalDifference(); m_CompareDetails.m_PixelsWithDifference = compare_filter->GetNumberOfPixelsWithDifferences(); mitk::Image::Pointer output = mitk::GrabItkImageMemory( compare_filter->GetOutput() ); this->SetOutput( MakeNameFromOutputIndex(0), output.GetPointer() ); } diff --git a/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp index 4571563a30..2227af2015 100644 --- a/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp +++ b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp @@ -1,190 +1,190 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // mitk includes #include "mitkMultiComponentImageDataComparisonFilter.h" #include "mitkImageReadAccessor.h" #include "mitkImagePixelReadAccessor.h" // other includes // #include namespace mitk { MultiComponentImageDataComparisonFilter::MultiComponentImageDataComparisonFilter(): ImageToImageFilter(), m_Tolerance(0.0f), m_CompareResult(false), m_CompareDetails(NULL) { this->SetNumberOfRequiredInputs(2); } MultiComponentImageDataComparisonFilter::~MultiComponentImageDataComparisonFilter() { } bool MultiComponentImageDataComparisonFilter::GetResult(double threshold) { if ( !m_CompareResult ) { return false; } if( m_CompareDetails->m_PixelsWithDifference > threshold ) { return false; } return true; } void MultiComponentImageDataComparisonFilter::SetValidImage( const Image *_arg ) { this->SetInput(0, _arg); } void MultiComponentImageDataComparisonFilter::SetTestImage( const Image *_arg ) { this->SetInput(1, _arg); } const Image* MultiComponentImageDataComparisonFilter::GetValidImage() { return this->GetInput(0); } const Image* MultiComponentImageDataComparisonFilter::GetTestImage() { return this->GetInput(1); } void MultiComponentImageDataComparisonFilter::SetCompareFilterResult( CompareFilterResults* results ) { m_CompareDetails = results; } CompareFilterResults* MultiComponentImageDataComparisonFilter::GetCompareFilterResult() { return m_CompareDetails; } void MultiComponentImageDataComparisonFilter::GenerateData() { // check inputs const Image* testInput = this->GetTestImage(); const Image* validInput = this->GetValidImage(); // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data // so no further image type comparison is performed! // CAVE: If the images differ in a parameter other then the image data, the filter may fail!! PixelType type = validInput->GetPixelType(); if(type.GetComponentType() == itk::ImageIOBase::CHAR) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::UCHAR) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::INT) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::UINT) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::SHORT) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::USHORT) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::LONG) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::ULONG) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::FLOAT) { CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::DOUBLE) { CompareMultiComponentImage( testInput, validInput); } else { mitkThrow() << "Pixel component type not supported!"; } } template void mitk::MultiComponentImageDataComparisonFilter::CompareMultiComponentImage( const Image* testImage, const Image* validImage ) { unsigned int noOfTimes = validImage->GetDimension(3); unsigned int noOfPixels = validImage->GetDimension(0)*validImage->GetDimension(1)*validImage->GetDimension(2); unsigned int noOfComponents = validImage->GetPixelType().GetNumberOfComponents(); for( unsigned int t = 0; t < noOfTimes; ++t) { ImageReadAccessor readAccTImage(const_cast(testImage), const_cast(testImage)->GetVolumeData(t)); ImageReadAccessor readAccVImage(const_cast(validImage), const_cast(validImage)->GetVolumeData(t)); for( unsigned int p = 0; p < noOfPixels*noOfComponents; ++p ) { TPixel vDataItem = static_cast(const_cast(readAccVImage.GetData()))[p]; TPixel tDataItem = static_cast(const_cast(readAccTImage.GetData()))[p]; if( tDataItem != vDataItem ) { ++m_CompareDetails->m_PixelsWithDifference; m_CompareDetails->m_MaximumDifference = std::max(m_CompareDetails->m_MaximumDifference, std::abs( static_cast(tDataItem - vDataItem) ) ); double min = std::min(m_CompareDetails->m_MinimumDifference, std::abs( static_cast(tDataItem - vDataItem) )); if(min != 0.0f) // a difference of zero is not a difference! m_CompareDetails->m_MinimumDifference = min; m_CompareDetails->m_TotalDifference += std::abs(static_cast(tDataItem - vDataItem) ); } } } - if(m_CompareDetails->m_PixelsWithDifference != 0) + if(m_CompareDetails->m_PixelsWithDifference > 0) { m_CompareDetails->m_MeanDifference = m_CompareDetails->m_TotalDifference / m_CompareDetails->m_PixelsWithDifference; m_CompareResult = false; } else { m_CompareResult = true; } - + m_CompareDetails->m_FilterCompleted = true; } } // end namespace mitk \ No newline at end of file