[Insight-users] Analyze IO
Gheorghe Postelnicu
gheorghe.postelnicu at gmail.com
Fri Dec 9 17:35:40 EST 2005
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> 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
> >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/560c551f/attachment.html
More information about the Insight-users
mailing list