[Insight-users] problems computing similarity between images
Petra Schneider
pschneid at TechFak . Uni-Bielefeld . DE
Wed, 20 Aug 2003 15:25:47 +0200
Hello,
my intention is very simple. I need to compute the similarity between different
regions of two images using NormalizedCorrelationImageToImageMetric (see my
code below).
But there seems to be a mistake. In some cases, I get the optimal metric value,
if I compare different regions of the same image. What's wrong? Need help.....
Thanks,
Petra
int main( int argc, char ** args )
{
typedef unsigned char pixel_value;
static const unsigned int image_dimension ( 2 );
typedef itk :: Image < pixel_value, image_dimension > image_type;
image_type :: Pointer image_fixed ( image_type :: New() );
image_type :: Pointer image_moving ( image_type :: New() );
typedef itk :: ImageFileReader < image_type > reader_type;
reader_type :: Pointer reader_fixed ( reader_type :: New() );
reader_type :: Pointer reader_moving ( reader_type :: New() );
reader_fixed -> SetFileName ( args[ 1 ] );
image_fixed = reader_fixed -> GetOutput();
image_fixed -> Update();
reader_moving -> SetFileName ( args[ 2 ] );
image_moving = reader_moving -> GetOutput();
image_moving -> Update();
typedef itk :: TranslationTransform < double, image_dimension >
transform_type;
typedef itk :: LinearInterpolateImageFunction < image_type, double >
interpolator_type;
typedef itk :: NormalizedCorrelationImageToImageMetric < image_type,
image_type > metric_type;
typedef itk :: ExtractImageFilter < image_type, image_type >
extractor_type;
typedef transform_type :: ParametersType parameters_type;
transform_type :: Pointer transform ( transform_type :: New() );
interpolator_type :: Pointer interpolator ( interpolator_type :: New()
);
metric_type :: Pointer metric ( metric_type :: New() );
extractor_type :: Pointer extractor ( extractor_type :: New() );
parameters_type parameters ( transform -> GetNumberOfParameters() );
for ( unsigned int i = 0; i < transform -> GetNumberOfParameters(); i++
)
{
parameters[ i ] = 0.0;
}
image_type :: RegionType region_moving;
image_type :: RegionType region_fixed;
image_type :: IndexType index_moving;
image_type :: IndexType index_fixed;
image_type :: SizeType size_moving;
image_type :: SizeType size_fixed;
index_moving[ 0 ] = 5; index_moving[ 1 ] = 0;
index_fixed[ 0 ] = 0; index_fixed[ 1 ] = 0;
size_moving[ 0 ] = 400; size_moving[ 1 ] = 395;
size_fixed[ 0 ] = 400; size_fixed[ 1 ] = 395;
region_moving.SetSize( size_moving );
region_moving.SetIndex( index_moving );
region_fixed.SetSize ( size_fixed );
region_fixed.SetIndex ( index_fixed );
extractor -> SetInput ( image_moving );
extractor -> SetExtractionRegion( region_moving );
extractor -> Update();
const image_type :: Pointer moving ( extractor -> GetOutput() );
moving -> Update();
image_fixed -> SetRegions ( region_fixed );
//image_fixed -> Allocate();
metric -> SetFixedImage ( image_fixed );
metric -> SetFixedImageRegion( image_fixed -> GetRequestedRegion() );
metric -> SetMovingImage( moving );
metric -> SetTransform ( transform );
metric -> SetTransformParameters ( parameters );
metric -> SetInterpolator ( interpolator );
metric -> Initialize();
cout << metric -> GetValue ( parameters ) << endl;
}