[Insight-users] PNG files to Analyze file

Kent Williams kent at psychiatry.uiowa.edu
Mon Oct 30 12:34:33 EST 2006


One of the great things about toolkits like ITK is that you can always 
read the source if you're puzzled by what a particular class is doing.  
If you look at Insight/Code/IO/itkImageSeriesReader.txx, it reads in two 
adjacent slices, and uses the 2D spacing of the images, and then 
computes the spacing for the 3rd dimension, by finding the distance 
between the origins of two consecutive slices.

PNG is a strictly 2D format, and while it will report the 2D spacing, 
and the origin for every slice is (0,0).

The Analyze file format doesn't record the image origin, so setting the 
origin of the image will be lost in the output file.  I'd recommend 
using another image format -- NIfTI comes to mine, because it's a 
complete, compact representation -- to store your image data if you care 
about preserving the origin.

The itk::ChangeInformationImageFilter requires you to explcitly tell it 
to change every attribute you want changed.  For example, to set the 
origin, spacing and orientation of an image using the filter you'd have 
to do something like this

// ImageType, myDirections, myOrigin, mySpacing declared elsewhere, this 
is a code fragment
typedef itk::ChangeInformationImageFilter<ImageType> 
ChangeInformationImageFilterType;
ChangeInformationImageFilterType::Pointer cf = 
ChaingeInformationImageFilterType::New();
cf->SetInput(myImage);
cf->ChangeSpacingOn(); cf->ChangeOriginOn(); cf->ChangeDirectionOn();
cf->SetUseReferenceImage(false);
cf->SetOutputDirection(myDirections);
cf->SetOutputOrigin(myOrigin);
cf->SetOutputSpacing(mySpacing);
cf->Update();
ImageType::Pointer myNewImage = cf->GetOutput();

Alan wrote:
> Hi folks!
>
> I am trying to convert a series of 2D slices (PNG files) to an Analyze
> file. For this purpose, I have started from the example in the software
> guide :
> Examples/IO/ImageSeriesReadWrite.cxx
> To set the inter-slice spacing of the 3D image of my set of
> PNG image, I am using the ChangeInformationImageFilter.
> However, I cannot manage to set the right spacing as well as the right
> origin of the Analyze file. What am I missing ? Do I need to use
> AnalyzeImageIO ?
> Thanks for any tips.
>
> Best regards,
>
> Alan
> _______________________________________________
> 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