[Insight-users] Similarity measure
Luis Ibanez
luis.ibanez@kitware.com
Sun May 16 16:34:32 EDT 2004
Hi Josiane,
With your two lines:
> typedef TransformType::ParametersType ParametersType;
> ParametersType displacement( transform->GetNumberOfParameters() );
You are creating an array of the correct size,
and passing it *unitialized* to the metric.
If you print out the values of "displacement"
array just before passing it to the metric,
you probably will find random garbage.
Since those values get used by the metric in order to
map one image onto the other, the transformation can
easily send the image so far that there is no overlap
between the fixed image and the transformed moving
image.
The message that you get:
"all the points mapped to outside
of the moving image"
indicates that there is no overlap between the
two images when the current transform paramterers
are used.
Please initialize the "displacement" array.
You could do it with something like:
displacements.Fill( 0.0 );
or depending on the image dimension, with
displacement[0] = 0.0; // along X
displacement[1] = 0.0; // along Y
displacement[2] = 0.0; // IFF IMAGE 3D !!, along Z
Then do
metric->Initialize();
std::cout << "Metric Value : " << metric->GetValue( displacement );
std::cout << "Tranf. Param : " << displacement << std::endl;
Regards,
Luis
-----------------------------------------------------
Josiane Yankam Njiwa--DEA Clarysse--Fin 11/04 wrote:
> Hi Luiz,
>
>
> Thanks for your help ones again.
> I have compile the code below, for the argument displacement you have
> introduce to Getvalue(), i have replace it by this way:
> typedef TransformType::ParametersType ParametersType;
> ParametersType displacement( transform->GetNumberOfParameters() );
> I have a message error during the execution and i don't know where i am
> doing wrong. The message error is:all the points mapped to outside of the
> moving image
>
>
> Do you know what is happened?
> Thanks + regards.
>
> Josiane.
>
>
>
>>Hi Josiane,
>>
>>
>>Many small details:
>>
>>
>>A) You are missing to connect the transform to the metric, like
>>
>> metric->SetTransform( transform );
>>
>>B) you are passing the transform as argument to the GetValue()
>> method of the metric. That shouldn't even compile... :-/
>> GetValue() expects an array of doubles, those are the
>> parameters for the transform.
>>
>>C) You are missing to connect an interpolator to the metric,
>> probably you want to use the NearestNeighborhood interpolator.
>>
>>D) You are not calling Initialize() in the metric before invoking
>> GetValue();
>>
>>
>>Please find attached the code that will do the Metric computation.
>>
>>
>>You will find useful to read the Registration chapter from the
>>SoftwareGuide.
>>
>>
>>Note also that if you have images that are already registered,
>>there are much faster and simpler ways to do this computation.
>>
>>
>>
>> Regards,
>>
>>
>>
>> Luis
>>
>>
>>
>>----------------------------------------------------------------------
>>Josiane Yankam Njiwa--DEA Clarysse--Fin 11/04 wrote:
>>
>>
>>>Hello
>>>
>>>
>>>I have two images and i want to calculate the square difference métric
>>>beetween the two images. I have the code below which is not work and
>>>return zero when i run the programm. Can you help me to solve my
>>>problem?
>>>Thanks for your help
>>>
>>>Josiane
>>>
>>>
>>>--------------------------------------------------------------------------
>>>typedef itk::MeanSquaresImageToImageMetric<
>>> FixedImageType,
>>> MovingImageType > MetricType;
>>>typedef itk::AffineTransform< PixelType, Dimension > TransformType;
>>>TransformType::Pointer transform = TransformType::New();
>>>MetricType::Pointer metric = MetricType::New();
>>>TransformType::OutputVectorType translation;
>>> translation[0] = 0; // X translation in millimeters
>>> translation[1] = 1; // Y translation in millimeters
>>> transform->Translate( translation );
>>> transform->Rotate2D(0,false);
>>>metric->SetFixedImage( fixedImageReader->GetOutput() );
>>>metric->SetMovingImage( caster->GetOutput() );
>>>metric->SetFixedImageRegion(
>>>fixedImageReader->GetOutput()->GetBufferedRegion() );
>>>const double bestValue = metric->GetValue(transform);
>>>std::cout << " Metric value = " << bestValue << std::endl;
>>>---------------------------------------------------------------------------
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users@itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>>-------------------------------------------------------------------
>>
>>
>>#include "itkImage.h"
>>#include "itkImageFileReader.h"
>>#include "itkImageFileWriter.h"
>>#include "itkMeanSquaresImageToImageMetric.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 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::MeanSquaresImageToImageMetric< 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();
>>
>>
>> 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 << "Mean Squares difference " << value << std::endl;
>>
>> return 0;
>>}
>>
>>
>
>
>
More information about the Insight-users
mailing list