[Insight-users] Analyze IO

Gheorghe Postelnicu gheorghe.postelnicu at gmail.com
Fri Dec 9 18:22:24 EST 2005


Karthik,

Thanks for this information! My suggestion is to have some kind of warning
message being written when that I/O function is called. Believe me, it can
help avoid a lot of confusion late at night.

Thanks again,

On 12/9/05, Karthik Krishnan <Karthik.Krishnan at kitware.com> wrote:
>
> Thanks for verifying. And please ignore the previous mail.
>
> I don't know if there is a way to specify an origin in Analyse files.
> This might be a limitation of the file format itself.
>
> From
> http://www.mayo.edu/bir/PDF/ANALYZE75.pdf
> there seems to be no field to specify the origin. The example provided
> above does not consider it either..
>
> In fact other software tools like SPM adopt their own heuristics:
>
> (From http://www.mrc-cbu.cam.ac.uk/Imaging/Common/analyze_fmt.shtml)
>
> "SPM modifications of the basic analyze format"
>
> The image origin is specified in the Originator field
> (data_history.originator - see Mayo/Analyze site). In the basic format,
> this is meant to be 10 bytes of text. In SPM, this space is used to
> contain three short (two byte) integers. These numbers describe the
> current centre or 'Origin' of the image. Specifically, they give the
> coordinate of the central voxel, in voxels, in X, then Y then Z. For
> example, for images that are aligned to the templates, this Origin field
> would contain the coordinates of the voxel nearest to the midline of the
> Anterior Commisure. Note that if the Origin is set to 0 0 0, then SPM
> routines will assume that the origin is in fact the central voxel of the
> image."
>
> Thanks
> Regards
> karthik
>
>
>
>
> Gheorghe Postelnicu wrote:
>
> > Actually I manually created the image (using the RawImageIO) and then
> > opted at first for .img extension when I was writing the file.
> >
> > Here is my code :
> >
> >
> > -----
> > template<class T>
> > static void
> > convert(VolumePars pars)
> > {
> >
> >   // declare types
> >
> >   typedef T PixelType;
> >   typedef typename itk::Image<PixelType,Dimension> ImageType;
> >   typedef typename itk::RawImageIO<PixelType,Dimension> ImageIOType;
> >   typedef typename itk::ImageFileReader<ImageType> ReaderType;
> >
> >
> >   typename ReaderType::Pointer reader = ReaderType::New();
> >   typename ImageIOType::Pointer rawIO = ImageIOType::New();
> >
> >
> >   rawIO->SetFileDimensionality(3);
> >   rawIO->SetOrigin(0, pars.originX);
> >   rawIO->SetOrigin(1, pars.originY);
> >   rawIO->SetOrigin(2, pars.originZ);
> >
> >   rawIO->SetDimensions(0, pars.dimX);
> >   rawIO->SetDimensions(1, pars.dimY);
> >   rawIO->SetDimensions(2, pars.dimZ);
> >
> >   rawIO->SetSpacing(0, pars.spacingX);
> >   rawIO->SetSpacing(1, pars.spacingY);
> >   rawIO->SetSpacing(2, pars.spacingZ);
> >
> >   rawIO->SetByteOrderToLittleEndian();
> >
> >   reader->SetFileName(pars.inputBuffer.c_str());
> >   reader->SetImageIO( rawIO );
> >
> >   try { reader->Update(); } catch(itk::ExceptionObject& excp)
> >     {
> >       std::cerr << "Exception caught while reading file " <<
> > reader->GetFileName() << std::endl
> >         << excp << std::endl;
> >       exit(1);
> >     }
> >
> >   std::cout << "done reading RAW image PARAMETERS\n"
> >         << "sizes = " <<
> > reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl
> >         << "origin = " << reader->GetOutput()->GetOrigin() << std::endl
> >         << "spacing = " << reader->GetOutput()->GetSpacing()  <<
> > std::endl;
> >
> >   typedef typename itk::ImageFileWriter<ImageType> WriterType;
> >   typename WriterType::Pointer writer = WriterType::New();
> >
> >   writer->SetFileName(pars.outputFileName.c_str());
> >   writer->SetInput(reader->GetOutput());
> >   try { writer->Update(); } catch(itk::ExceptionObject& excp)
> >     {
> >       std::cerr << "Exception caught while writing\n"
> >         << excp << std::endl;
> >       exit(1);
> >     }
> >
> > }
> >
> > ------
> >
> > As you can see, the origin of the image is displayed before the image
> > is saved.
> >
> > After noticing that I had some placement problems, I wrote another
> > binary which was just loading an image in ITK and displaying the
> > information. When using the .img extension, the origin information was
> > lost.
> >
> > I looked very briefly in the itkAnalyzeImageIO.cxx file and it appears
> > some origin information is written in some metadata associated with
> > the image. I have seen on the internet some proposal to include
> > orientation information which used the same mechanism.
> >
> > Thanks,
> >
> > On 12/9/05, *Karthik Krishnan* <Karthik.Krishnan at kitware.com
> > <mailto:Karthik.Krishnan at kitware.com>> wrote:
> >
> >     Please let us know what format you converted from ? The bug might be
> >     that the origin data was never read in .
> >
> >     I've written analyse images in ITK before and they seem to retain
> the
> >     origin information.
> >
> >     I have observed that InsightApplications/ImageViewer does not
> respect
> >     image origins when it reads files. So are you basing your
> >     assumptions on
> >     images seen using ImageViewer ? If you use any of the several other
> >     viewers, you should find that the origin info is recorded.
> >
> >     thanks
> >     karthik
> >
> >     Gheorghe Postelnicu wrote:
> >
> >     > Hi,
> >     >
> >     > I have recently used ITK to convert some files to the Analyze
> format
> >     > and I have noticed that the origin data is lost when writing the
> >     > volume file. I haven't gone further than this, but is this normal?
> >     >
> >     > As far as I am concerned, this is quite annoying when doing
> >     registration.
> >     >
> >     > Thanks,
> >     > --
> >     > Gheorghe Postelnicu, PhD
> >     > MGH, Harvard Medical School
> >     >
> >
> >------------------------------------------------------------------------
> >     >
> >     >_______________________________________________
> >     >Insight-users mailing list
> >     >Insight-users at itk.org <mailto:Insight-users at itk.org>
> >     >http://www.itk.org/mailman/listinfo/insight-users
> >     >
> >     >
> >
> >
> >
> >
> > --
> > Gheorghe Postelnicu, PhD
> > MGH, Harvard Medical School
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >Insight-users mailing list
> >Insight-users at itk.org
> >http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>



--
Gheorghe Postelnicu, PhD
MGH, Harvard Medical School
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20051209/a6750d47/attachment.html


More information about the Insight-users mailing list