Karthik,<br>
<br>
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.<br>
<br>
Thanks again,<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;">
Thanks for verifying. And please ignore the previous mail.<br><br>I don't know if there is a way to specify an origin in Analyse files.<br>This might be a limitation of the file format itself.<br><br> From<br><a href="http://www.mayo.edu/bir/PDF/ANALYZE75.pdf">
http://www.mayo.edu/bir/PDF/ANALYZE75.pdf</a><br>there seems to be no field to specify the origin. The example provided<br>above does not consider it either..<br><br>In fact other software tools like SPM adopt their own heuristics:
<br><br>(From <a href="http://www.mrc-cbu.cam.ac.uk/Imaging/Common/analyze_fmt.shtml">http://www.mrc-cbu.cam.ac.uk/Imaging/Common/analyze_fmt.shtml</a>)<br><br>"SPM modifications of the basic analyze format"<br>
<br>The image origin is specified in the Originator field<br>(data_history.originator - see Mayo/Analyze site). In the basic format,<br>this is meant to be 10 bytes of text. In SPM, this space is used to<br>contain three short (two byte) integers. These numbers describe the
<br>current centre or 'Origin' of the image. Specifically, they give the<br>coordinate of the central voxel, in voxels, in X, then Y then Z. For<br>example, for images that are aligned to the templates, this Origin field<br>
would contain the coordinates of the voxel nearest to the midline of the<br>Anterior Commisure. Note that if the Origin is set to 0 0 0, then SPM<br>routines will assume that the origin is in fact the central voxel of the
<br>image."<br><br>Thanks<br>Regards<br>karthik<br><br><br><br><br>Gheorghe Postelnicu wrote:<br><br>> Actually I manually created the image (using the RawImageIO) and then<br>> 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 " <<
<br>> reader->GetFileName() << std::endl<br>> << excp << std::endl;<br>> exit(1);<br>> }<br>><br>> std::cout << "done reading RAW image PARAMETERS\n"
<br>> << "sizes = " <<<br>> reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl<br>>
<< "origin = " << reader->GetOutput()->GetOrigin()
<< std::endl<br>>
<< "spacing = " <<
reader->GetOutput()->GetSpacing() <<<br>> 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
<br>> is saved.<br>><br>> After noticing that I had some placement problems, I wrote another<br>> binary which was just loading an image in ITK and displaying the<br>> information. When using the .img extension, the origin information was
<br>> lost.<br>><br>> I looked very briefly in the itkAnalyzeImageIO.cxx file and it appears<br>> some origin information is written in some metadata associated with<br>> the image. I have seen on the internet some proposal to include
<br>> orientation information which used the same mechanism.<br>><br>> Thanks,<br>><br>> On 12/9/05, *Karthik Krishnan* <<a href="mailto:Karthik.Krishnan@kitware.com">Karthik.Krishnan@kitware.com</a><br>
> <mailto:<a href="mailto:Karthik.Krishnan@kitware.com">Karthik.Krishnan@kitware.com</a>>> wrote:<br>><br>> 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
<br>> 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<br>> 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> <mailto:<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>><br>><br>><br>
><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