[Insight-users] Compare images by mean square difference
Marta
t_s_80 at gmx.de
Thu Jan 29 09:19:20 EST 2009
Hello,
I simply want to compare two images (without registration) by mean
square value. All I have found to do so, is the
MeanSquaresImageToImageMetric that is also used for
registration. Is it correct to use it also in my case?
I wrote a method (you can see below) that get two identical images,
apart from the image content (same size, same spacing, same origin).
It is working, but the results can't be right. The values are very
large, even if the content of the images is equal. What is wrong with
my method? Did I forget something?
Or is it wrong to use the Metric this way?
Thanks a lot for your help,
Marta
--------------------------------------------------------------------------------------------------------------------
void THIS::calculateMeanSquaresErrorBetweenImages( ImageType::Pointer
image1, ImageType::Pointer image2 ) {
/*
//This part is actually in the header:
int Dimension = 2;
typedef unsigned short InputPixelType;
typedef unsigned short OutputPixelType;
typedef itk::Image< InputPixelType, Dimension > ImageType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::RescaleIntensityImageFilter< ImageType, OutputImageType
> RescaleFilterType;*/
typedef itk::MeanSquaresImageToImageMetric< OutputImageType,
OutputImageType > MetricType;
typedef itk::LinearInterpolateImageFunction< OutputImageType >
LinearInterpolatorType;
typedef itk::CenteredRigid2DTransform< double > TransformType;
RescaleFilterType::Pointer rescaler1 = RescaleFilterType::New( );
RescaleFilterType::Pointer rescaler2 = RescaleFilterType::New( );
rescaler1->SetOutputMinimum( 0 );
rescaler1->SetOutputMaximum( 65535 );
rescaler2->SetOutputMinimum( 0 );
rescaler2->SetOutputMaximum( 65535 );
rescaler1->SetInput( image1 );
rescaler2->SetInput( image2 );
LinearInterpolatorType::Pointer interpolator =
LinearInterpolatorType::New( );
OutputImageType::Pointer image1 = rescaler1->GetOutput( );
OutputImageType::Pointer image2 = rescaler2->GetOutput( );
rescaler1->Update( );
rescaler2->Update( );
MetricType::Pointer metric = MetricType::New( );
metric->SetFixedImage( image1 );
metric->SetMovingImage( image2 );
metric->SetFixedImageRegion( image1->GetLargestPossibleRegion( ) );
TransformType::Pointer transform = Transform::TransformType::New( );
transform->SetIdentity( );
metric->SetTransform( transform );
metric->SetTransformParameters ( transform->GetParameters( ) );
metric->SetInterpolator( interpolator );
metric->Initialize( );
std::cout << "Metrik Value: " << metric->GetValue( transform-
>GetParameters( ) ) << std::endl;
}
More information about the Insight-users
mailing list