[Insight-users] segmentation evaluation metrics help
abatzis at ceid.upatras.gr
abatzis at ceid.upatras.gr
Tue Oct 14 06:55:55 EDT 2008
Dear Luis/All,
i want to compare two binary images(foreground->255, background->0) by use
of the appropriate metrics such as itkContourMeanDistanceImageFilter,
itkHausdorffDistanceImageFilter and itkKappaStatisticImageToImageMetric.
Unfortunately havent found the way to do so since now. Below i state some
code so as to speak in a more practical basis. If anyone has successfully
deployed these metrics, let he gives me a hint.(i just fixed the input
fragment of the code below and copied the other from the corresponding
metrics tests in itk though i dont really understand it).
Thanks in advance
Jim
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkKappaStatisticImageToImageMetric.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkTranslationTransform.h"
#include "itkContourMeanDistanceImageFilter.h"
#include "itkContourDIrectedMeanDistanceImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkFilterWatcher.h"
#include "itkDirectedHausdorffDistanceImageFilter.h"
#include "itkHausdorffDistanceImageFilter.h"
int main( int argc, char *argv[] ) {
if( argc < 2 ) {
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage1 inputImage2";
return 1;
}
typedef unsigned char PixelType;
//typedef float Pixel2Type;
const int ImageDimension = 3 ;
typedef itk::Image<PixelType,ImageDimension> ImageType;
//typedef itk::Image<Pixel2Type,ImageDimension> ImageManualType;
typedef itk::ImageFileReader<ImageType> ReaderType;
// typedef itk::ImageFileReader<Image2Type> ReaderType2;
ReaderType::Pointer reader1 = ReaderType::New();
ReaderType::Pointer reader2 = ReaderType::New();
ImageType::Pointer image1 = ImageType::New();
ImageType::Pointer image2 = ImageType::New();
reader1->SetFileName(argv[1]);
reader2->SetFileName(argv[2]);
try {
reader1->Update();
reader2->Update();
}
catch( itk::ExceptionObject & excep ) {
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
ImageType::SizeType size1, size2;
size1 = reader1->GetOutput()->GetBufferedRegion().GetSize();
size2 = reader2->GetOutput()->GetBufferedRegion().GetSize();
image1->SetRegions( size1 );
image2->SetRegions( size2 );
image1->Allocate();
image2->Allocate();
image1->FillBuffer( itk::NumericTraits<PixelType>::Zero );
image2->FillBuffer( itk::NumericTraits<PixelType>::Zero );
typedef ImageType::RegionType RegionType;
RegionType region1;
RegionType region2;
typedef ImageType::IndexType IndexType;
IndexType index1;
IndexType index2;
index1 = reader1->GetOutput()->GetBufferedRegion().GetIndex();
index2 = reader2->GetOutput()->GetBufferedRegion().GetIndex();
//size.Fill( 20 );
//index.Fill( 10 );
region1.SetSize( size1 );
region1.SetIndex( index1 );
region2.SetSize( size2 );
region2.SetIndex( index2 );
itk::ImageRegionIterator<ImageType> it1( image1, region1 );
PixelType count = itk::NumericTraits<PixelType>::Zero;
while ( !it1.IsAtEnd() )
{
it1.Set( ++count );
++it1;
}
itk::ImageRegionIterator<ImageType> it2( image2, region2 );
while ( !it2.IsAtEnd() )
{
it2.Set( 7.2 );
++it2;
}
typedef itk::ContourDirectedMeanDistanceImageFilter<ImageType,ImageType>
FilterType1; //ContourDirectedMeanDistance(im1,im2)
FilterType1::Pointer filter1 = FilterType1::New();
FilterWatcher watcher1(filter1, "filter");
filter1->SetInput1( image1 );
filter1->SetInput2( image2 );
filter1->Update();
filter1->Print( std::cout );
FilterType1::RealType distance1 =
filter1->GetContourDirectedMeanDistance();
std::cout << " Computed distance1: " << distance1 << std::endl;
typedef itk::ContourDirectedMeanDistanceImageFilter<ImageType,ImageType>
FilterType2; //ContourDirectedMeanDistance(im2,im1)
FilterType2::Pointer filter2 = FilterType2::New();
FilterWatcher watcher2(filter2, "filter");
filter2->SetInput1( image2 );
filter2->SetInput2( image1 );
filter2->Update();
FilterType2::RealType distance2 =
filter2->GetContourDirectedMeanDistance();
std::cout << " Computed distance2: " << distance2 << std::endl;
return EXIT_SUCCESS;
}
More information about the Insight-users
mailing list