[Insight-users] transform an image problem

Moti Freiman freiman at cs.huji.ac.il
Tue Sep 28 10:09:47 EDT 2010


Hi,
Thanks for the fast answer.
I added the direction code as you can see below. Problem still not solved yet.
I think that I handle the origin, and orientation well now.
Any other suggestion?
Thanks,
Moti



resampler->SetOutputSpacing( fixedImage->GetSpacing() );
resampler->SetSize(  fixedImage->GetLargestPossibleRegion().GetSize() );
resampler->SetOutputOrigin( fixedImage->GetOrigin());
resampler->SetOutputDirection(movingImage->GetDirection());

On Tue, Sep 28, 2010 at 9:27 AM, Vincent Magnotta
<vincent-magnotta at uiowa.edu> wrote:
> Moti,
>
> The number one reason for this type of error is not correctly handling the
> origin and orientation in the images. Just quickly looking at the code, you
> should also set the direction of the output image.
>
> Vince
>
>
>
> On 9/28/10 8:22 AM, "Moti Freiman" <freiman at cs.huji.ac.il> wrote:
>
>> Hi All,
>> I have an affine transformation that I produced using the ICP
>> algorithm as implemented in VTK.
>> Now I want to transfer the original moving image to the coordinates of
>> the fixed one.
>>
>> I wrote a simple ITK based application, that read the images and the
>> transform, and apply the trasnform to the moving image.
>> However, It seems that I got an empty image (with default value),
>> although the transformation of the surfaces using VTK works well.
>> I tested the transformation by transforming several points using both
>> ITK transform and the VTK transform, and the points transffered
>> indentically.
>> Does any one has an idea, some expirience with that problem.
>>
>> The code is attached bellow
>> Best,
>> Moti
>>
>>
>>
>>
>> --------------------------------- ITK based affine image
>> transformation -------------------------------------------
>>
>>         // declare the affine transfrom
>> typedef itk::AffineTransform <double,Dimension> itkAffineTransformType;
>> itkAffineTransformType::Pointer trans = itkAffineTransformType::New();
>> trans->SetIdentity();
>>
>> // read transform params from file
>> std::fstream transFile;
>> transFile.open (inputReferenceToPatientTransformFileName.c_str(),
>> std::ios::in);
>> int numOfElements = Dimension*Dimension;
>>
>> itkAffineTransformType::MatrixType matrix;
>> itkTranslationTransformType::OutputVectorType translation;
>>
>> for (int i=0;i<Dimension;++i)
>> {
>> for (int j=0;j<Dimension;++j)
>> {
>> transFile >> matrix(i,j);
>> }
>> }
>> dout << "end to read matrix" << std::endl;
>> for (int i=0;i<Dimension;++i)
>> {
>> transFile >> translation[i];
>> translation[i]  = -translation[i];
>>
>> }
>>
>> transFile.close();
>>
>>
>>
>> trans->SetMatrix( matrix );
>> trans->SetOffset(translation);
>>
>>         // transform some point for testing purpose
>> dout << trans << std::endl;
>> itkAffineTransformType::InputPointType inPoint;
>> inPoint[0] = 1;  inPoint[1] = 1; inPoint[2] = 1;
>> itkAffineTransformType::OutputPointType outPoint =
>> trans->TransformPoint(inPoint);
>> dout << outPoint[0] << ", " << outPoint[1] << ", " << outPoint[2] <<
>> std::endl;
>>
>>
>>         // resample the moving image
>>         typedef itk::ResampleImageFilter< LabelsImageType,
>> LabelsImageType > ResampleFilterType;
>> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
>>
>>
>>
>> typedef itk::NearestNeighborInterpolateImageFunction<LabelsImageType,
>> double> InterpolatorType;
>> InterpolatorType::Pointer interpolator = InterpolatorType::New();
>> resampler->SetInterpolator( interpolator );
>> resampler->SetTransform( trans );
>> resampler->SetDefaultPixelValue(100);
>> resampler->SetOutputSpacing( fixedImage );
>> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
>> resampler->SetOutputOrigin( fixedImage->GetOrigin());
>> resampler->SetInput (movingImage);
>>
>>
>> resampler->Update();
>>
>>
>> ------------------------------------------ end of code
>> --------------------------------------------------------------
>
> ----------------------
> Associate Professor
> Department of Radiology
> 0453-D JCP
> 200 Hawkins Drive
> Iowa City, IA 52242
> E-mail: vincent-magnotta at uiowa.edu
> Phone: 319-356-8255 Fax: 319-353-6275
> Website: http://www.radiology.uiowa.edu
>
>
>
>



-- 
__
Moti Freiman, Postdoctoral Associate,
Harvard Medical School.
Research Fellow,
Computational Radiology Laboratory.
Dept. of Radiology, Children's hospital,
300 Longwood Ave. Boston, MA 02115.

Lab website: http://crl.med.harvard.edu


More information about the Insight-users mailing list