[Insight-users] loss of spacing and origin when feeding an itkImage to itkWriter
Luis Ibanez
luis.ibanez at kitware.com
Tue May 6 11:43:50 EDT 2008
Hi Peter,
If you image was taken as the output of an ITK filter,
you shouldn't change the image metadata directly
(e.g. origin, spacing, direction).
Instead, you should use the
ChangeInformationImageFilter:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html
Something like :
changeFilter->SetInput( reader->GetOutput() );
changeFilter->SetOutputOrigin( newOrigin );
changeFilter->ChangOriginOn();
Otherwise, the changes that you are applying manually
to your image will get lost as soon as a call to Update()
is made in any filter downstream the pipeline.
Output images are "own" by the filter that compute
them.
BTW, please note that changing image information in a
clinical environment is a *very dangerous* thing
to do. You shoud really be very sure that you
want to override the image metadata.
Regards,
Luis
---------------------------
Boettcher, Dr. Peter wrote:
> I have problems feeding an itkImage to itkWriter. During that process
> the parameters image spacing and image origin are lost!
>
>
>
> During my image pipeline I define image = caster->GetOutput().
>
>
>
> caster2D->Update();
>
> imageCastFix = caster2D->GetOutput();
>
>
>
> Then I do some changes to the image spacing and origin:
>
>
>
> imageCastFix->SetOrigin(origin2D);
> imageCastFix->SetSpacing(spacing2D);
> imageCastFix->Modified();
>
>
>
> Checking whether the changes were made
>
>
>
> imageCastFix->Print( std::cout );
>
>
>
> …
>
> Spacing 0.576 0.576 0.576
>
> Origin: -124.5 -124.5 -124.5
>
> …
>
>
>
> Up to this point every thing works as I expected. The image spacing and
> origin I changes manually was assigned to the image.
>
>
>
> However when I feed the modified image to an ImageWriter
>
>
>
> writerFluo->SetInput( imageCastFix);
>
> writerFluo ->Update();
>
>
>
> The image file written onto my disk has an image spacing of 1 1 1 and
> origin 0 0 0.
>
>
>
> Any idea why the parameters of my image are not passed to the image writer?
>
> This effect is independent of the image file type I define.
>
>
>
> Regards, Peter.
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list