Actually I manually created the image (using the RawImageIO) and then
opted at first for .img extension when I was writing the file.<br>
<br>
Here is my code :<br>
<br>
<br>
-----<br>
template<class T><br>
static void<br>
convert(VolumePars pars)<br>
{<br>
<br>
// declare types<br>
<br>
typedef T PixelType;<br>
typedef typename itk::Image<PixelType,Dimension> ImageType;<br>
typedef typename itk::RawImageIO<PixelType,Dimension> ImageIOType;<br>
typedef typename itk::ImageFileReader<ImageType> ReaderType;<br>
<br>
<br>
typename ReaderType::Pointer reader = ReaderType::New();<br>
typename ImageIOType::Pointer rawIO = ImageIOType::New();<br>
<br>
<br>
rawIO->SetFileDimensionality(3);<br>
rawIO->SetOrigin(0, pars.originX);<br>
rawIO->SetOrigin(1, pars.originY);<br>
rawIO->SetOrigin(2, pars.originZ);<br>
<br>
rawIO->SetDimensions(0, pars.dimX);<br>
rawIO->SetDimensions(1, pars.dimY);<br>
rawIO->SetDimensions(2, pars.dimZ);<br>
<br>
rawIO->SetSpacing(0, pars.spacingX);<br>
rawIO->SetSpacing(1, pars.spacingY);<br>
rawIO->SetSpacing(2, pars.spacingZ);<br>
<br>
rawIO->SetByteOrderToLittleEndian();<br>
<br>
reader->SetFileName(pars.inputBuffer.c_str());<br>
reader->SetImageIO( rawIO );<br>
<br>
try { reader->Update(); } catch(itk::ExceptionObject& excp)<br>
{<br>
std::cerr << "Exception caught
while reading file " << reader->GetFileName() <<
std::endl<br>
<< excp << std::endl;<br>
exit(1);<br>
}<br>
<br>
std::cout << "done reading RAW image PARAMETERS\n"<br>
<< "sizes = " <<
reader->GetOutput()->GetLargestPossibleRegion().GetSize()
<< std::endl<br>
<< "origin = " << reader->GetOutput()->GetOrigin() << std::endl<br>
<< "spacing = " <<
reader->GetOutput()->GetSpacing() << std::endl;<br>
<br>
typedef typename itk::ImageFileWriter<ImageType> WriterType;<br>
typename WriterType::Pointer writer = WriterType::New();<br>
<br>
writer->SetFileName(pars.outputFileName.c_str());<br>
writer->SetInput(reader->GetOutput());<br>
try { writer->Update(); } catch(itk::ExceptionObject& excp)<br>
{<br>
std::cerr << "Exception caught while writing\n"<br>
<< excp << std::endl;<br>
exit(1);<br>
}<br>
<br>
}<br>
<br>
------<br>
<br>
As you can see, the origin of the image is displayed before the image is saved.<br>
<br>
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.<br>
<br>
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.<br>
<br>Thanks,<br>
<br>
<div><span class="gmail_quote">On 12/9/05, <b class="gmail_sendername">Karthik Krishnan</b> <<a href="mailto:Karthik.Krishnan@kitware.com">Karthik.Krishnan@kitware.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Please let us know what format you converted from ? The bug might be<br>that the origin data was never read in .<br><br>I've written analyse images in ITK before and they seem to retain the<br>origin information.<br><br>I have observed that InsightApplications/ImageViewer does not respect
<br>image origins when it reads files. So are you basing your assumptions on<br>images seen using ImageViewer ? If you use any of the several other<br>viewers, you should find that the origin info is recorded.<br><br>thanks
<br>karthik<br><br>Gheorghe Postelnicu wrote:<br><br>> Hi,<br>><br>> I have recently used ITK to convert some files to the Analyze format<br>> and I have noticed that the origin data is lost when writing the<br>
> volume file. I haven't gone further than this, but is this normal?<br>><br>> As far as I am concerned, this is quite annoying when doing registration.<br>><br>> Thanks,<br>> --<br>> Gheorghe Postelnicu, PhD
<br>> MGH, Harvard Medical School<br>><br>>------------------------------------------------------------------------<br>><br>>_______________________________________________<br>>Insight-users mailing list
<br>><a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>><a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br>><br>><br></blockquote>
</div><br><br clear="all"><br>-- <br>Gheorghe Postelnicu, PhD<br>MGH, Harvard Medical School