[Insight-users] Re: Simple question on raw file reading

Phillip Cheng pmcheng@u.washington.edu
Tue, 4 Mar 2003 09:37:35 -0800


Hi Luis,

Thanks for your message.  MetaImage file reading does seem to work ok 
on the Mac, and the header looks easy to synthesize.  The original 
image did come with its own header, but a proprietary one (from our GE 
PET scanner).

I got tangled in raw file reading in the first place because I was 
trying to get the MultiResMIRegistration application working from 
InsightApplications (it looks quite close to something we could use 
right now).  On Mac OS X, I get "Read failed" error messages just like 
the one I cited earlier.  It looks like this application also depends 
on raw file reading, wrapped in the RawVolumeReader template from 
IBSRValidation/Common.

Phillip


> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
> Sent: Tuesday, March 04, 2003 7:44 AM
> To: Phillip Cheng
> Cc: insight-users@public.kitware.com
> Subject: Re: [Insight-users] Simple question on raw file reading
>
>
>
> 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
>>
>
> ==========================================
>
>
>
> <image.mhd>