[Insight-users] problem when calculating metric values between two
images
Ming Chao
mingchao2005 at gmail.com
Wed Feb 15 17:45:10 EST 2006
HI again,
For some reason, my message was discarded when I sent it to the mailing list
the first time. I am sending it again. The two images can be found:
http://www.stanford.edu/~mingchao/image/fixedImage.vtk
and
http://www.stanford.edu/~mingchao/image/movingImage16.vtk
Hi,
I followed a standard procedure to calculate the metric between two images.
However, I encountered a problem. Bascally I have two images which are
subregions of a big image. When I calculate the metric between these two
smaller images, the metric value is always -1 (I am using Normalized
Correlation Metric). The code is attached to the end of this message. And
the two images are attached as well. I don't understand what is wrong.
Thanks,
Ming
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMeanSquaresImageToImageMetric.h"
#include "itkNormalizedCorrelationImageToImageMetric.h "
#include "itkTranslationTransform.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkLinearInterpolateImageFunction.h"
int main( int argc, char * argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " fixedImage movingImage" << std::endl;
return 1;
}
const unsigned int Dimension = 2;
//typedef unsigned char PixelType;
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer fixedReader = ReaderType::New();
ReaderType::Pointer movingReader = ReaderType::New();
fixedReader->SetFileName( argv[ 1 ] );
movingReader->SetFileName( argv[ 2 ] );
try
{
fixedReader->Update();
movingReader->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
typedef itk::NormalizedCorrelationImageToImageMetric< ImageType, ImageType
> MetricType;
MetricType::Pointer metric = MetricType::New();
typedef itk::TranslationTransform< double, Dimension > TransformType;
TransformType::Pointer transform = TransformType::New();
typedef itk::NearestNeighborInterpolateImageFunction<
ImageType, double > InterpolatorType;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
typedef TransformType::ParametersType ParametersType;
ParametersType displacement( transform->GetNumberOfParameters() );
displacement.Fill( 0.0 );
metric->SetInterpolator( interpolator );
metric->SetTransform( transform );
//transform->SetIdentity();
ImageType::ConstPointer fixedImage = fixedReader->GetOutput();
ImageType::ConstPointer movingImage = movingReader->GetOutput();
metric->SetFixedImage( fixedImage );
metric->SetMovingImage( movingImage );
metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );
try
{
metric->Initialize();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
return -1;
}
const double value = metric->GetValue( displacement );
std::cout << "metric value == " << value << std::endl;
std::cout << "displacement = " << displacement << std::endl;
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060215/b68f2797/attachment.htm
More information about the Insight-users
mailing list