[Insight-users] Simple question on raw file reading

Luis Ibanez luis.ibanez@kitware.com
Tue, 04 Mar 2003 10:44:11 -0500


This is a multi-part message in MIME format.
--------------090200010209080702080601
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


Hi Phillip,

Your code looks ok,

Could you please do an experiment for us ?

Attached is a MetaImage header file that has
been customized for your Raw Image.

This header file was created using the
application MetaImageImporter available in

    InsightApplications/MetaImageImporter

If you put this attached file in the same
directory where your "pet.img" file is, you
will be able to use the ImageFileReader<> and
the default factory mechanism for reading your
image.

Make sure that you provide the filename
"image.mhd" to the image file reader
using SetFileName(), and do not set the
ImageIO. The factory mechanism will select
the right ImageIO based on the extension
of the inpur file.

Please let us know if this work for reading
your image.

That will help us to determine if the Raw
reader is miss-behaving in the Mac. BTW
I'm not that user of the endianness, so,
you may want to switch this entry in the
image.mhd (this is a text file that you can
modify with any editor).

Note that in general there is no good reason
for using the RawImageIO reader instead of
creating a MetaImage header and using the
MetaImage reader. You could do a similar
thing with the VTK image format.

RAW is an intrinsically useless and dangerous
format because it is incomplete. In practice
anyone who pass you a Raw image file has
to give you the "header" information by any
other media (ranging from a napkin, to a post-it
or an email :-)).


Please let us know what you find,


   Thanks


    Luis


------------------------------

Phillip Cheng wrote:
> Hello,
> 
> I'm new to ITK and am trying to read in a simple raw image volume, but 
> I'm not sure what I'm doing wrong.  I'm running the current ITK CVS on 
> Mac OS X 10.2.4.  Here's a sample:
> 
> ====================================================
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkRawImageIO.h"
> 
> int main()
> {
>     typedef itk::Image<float,3> ImageType;
> 
>     typedef itk::ImageFileReader<ImageType> ReaderType;
>     ReaderType::Pointer reader=ReaderType::New();
> 
>     typedef itk::RawImageIO<float,3> ImageIOType;
>     ImageIOType::Pointer rawImageIO=ImageIOType::New();
> 
>     reader->SetImageIO(rawImageIO);
>     reader->SetFileName("pet.img");
> 
>     rawImageIO->SetByteOrderToBigEndian();
>     rawImageIO->SetFileTypeToBinary();
>     rawImageIO->SetFileDimensionality(3);
> 
>     rawImageIO->SetOrigin(0,0.0);
>     rawImageIO->SetOrigin(1,0.0);
>     rawImageIO->SetOrigin(2,0.0);
> 
>     rawImageIO->SetDimensions(0,128);
>     rawImageIO->SetDimensions(1,128);
>     rawImageIO->SetDimensions(2,36);
> 
>     rawImageIO->SetSpacing(0,4.3);
>     rawImageIO->SetSpacing(1,4.3);
>     rawImageIO->SetSpacing(2,4.25);
> 
>     try
>     {
>     reader->Update();
>     }
>     catch(itk::ExceptionObject& err)
>     {
>     std::cout << "Error: "<< err << std::endl;
>     }
> }
> ============================================
> 
> When I run this, I get the following message:
> 
> Error:
> itk::ExceptionObject (0x1c6230)
> Location: "Unknown"
> File: /Users/pmcheng/ITK/Insight/Code/IO/itkRawImageIO.txx
> Line: 190
> Description: itk::ERROR: RawImageIO(0x1c4070): Read failed: Wanted 
> 2359296 bytes, but read 2359296 bytes.
> 
> 
> I'm not sure what this error means.  The file "pet.img" that I'm trying 
> to load is exactly 2359296 bytes and is a big-endian 128x128x36 floating 
> point array.
> 
> Thanks for any help.
> 
> Phillip Cheng
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 

==========================================




--------------090200010209080702080601
Content-Type: text/plain;
 name="image.mhd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="image.mhd"

NDims = 3
DimSize = 128 128 36
ElementSpacing = 4.3 4.3 4.25
Position = 0 0 0
ElementByteOrderMSB = False
ElementType = MET_FLOAT
HeaderSize = -1
ElementDataFile = pet.img

--------------090200010209080702080601--