[Insight-users] transform an image problem

Moti Freiman freiman at cs.huji.ac.il
Sun Oct 17 20:57:34 EDT 2010


Hi,
Thanks for the response,
I already solved my problem.
Thanks,
Moti

On Sun, Oct 17, 2010 at 11:03 AM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Moti,
>
> Did you set the Center of rotation
>  in the Affine Transform ?
>
> ---
>
> and yet, a better solution,
>
> you could use directly ICP implementation in ITK,
> and fee it with points that have been harvested
> using the:
>
>                    IndexToPhysicalPoint()
>
> method of the itkImages.
>
> In that way you will be sure of using points
> that are really in the same coordinate system
> as the images.
>
> It is quite likely that the point coordinates
> that you used as input for the VTK ICP
> algorithm, do not map to the locations
> that you are expecting in the ITK images.
>
>
> Also, keep in mind that VTK and ITK
> have a reflection in the coordinates of
> the Y axis... this may also be playing
> here...
>
>
>
>     Regards,
>
>
>          Luis
>
>
> ------------------------------------------------------
> On Tue, Sep 28, 2010 at 10:09 AM, Moti Freiman <freiman at cs.huji.ac.il>
> wrote:
>>
>> 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
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>
>



-- 
__
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