[Insight-users] reading raw data : write a MetaImage header

Luis Ibanez luis . ibanez at kitware . com
Thu, 30 Oct 2003 20:15:39 -0500


Hi Lorenzo,

The easy way to load RAW data into ITK images
is to first write a MetaImage header.

This is a simple text file that you must put
in the same directory where your raw image
file is.  Let's call this header file "Image.mhd",
the content of this file corresponding to your
image will be the following text:


NDims = 3
DimSize = 250 256 20
ElementSpacing = 1 1 1
Position = 0 0 0
ElementByteOrderMSB = False
ElementType = MET_USHORT
ElementDataFile = saCine.slice14.256x256x20



That's all.

It is a 3D image, with dimensions 250x256x20
The ElementSpacing here is 1x1x1 but your MRI
was probably sampled with a longer pixel spacing
in Z. (interslice spacing). Please make sure that
your replace this dummy 1.0s with the righ values
in millimeters.

Your ITK code looks fine. Simply make sure that
you pass as argument the name of the metaimage
header "Image.mhd".


---

BTW the Abort message that you get is due to an
exception being trown.  A call to an Update() method
should be put inside a try/catch block like:


try
   {
   reader->Update();
   }
catch( itk::ExceptionObject & excp )
   {
   std::cerr << "Problem reading data " << std::endl;
   std::cerr << excp << std::endl;
   }



Please let us know if you find further problems.


Thanks


    Luis



---------------------------
Lucas Lorenzo wrote:
> Hi all,
> before starting I want to apologize for the basic content of my inquiry 
> but I'm just learning ITK.
> 
> 1) I'm trying to read some MRI data consisting of 20 slices of 250x256 
> pixels each.
> 2) The data is stored as unsigned short.
> 3) I was previously using Matlab and this is the code I used to read it:
> 
>    ff=fopen('saCine.slice14.256x256x20','r','ieee-be');
>    slice=fread(ff,'ushort');
>    fclose(ff);
>    number_of_slcs=length(slice)/(256^2);
>    slice=reshape(slice,[256 256 number_of_slcs]);
> 
> 4) I tried the following code in C++ (it's a copy of Image2.cxx except 
> that I changed the PixelType
> 
>     #include "itkImage.h"
>     #include "itkImageFileReader.h"
> 
>     int main( int argc, char *argv[])
>     {
>       typedef unsigned short          PixelType;
>       const unsigned int             Dimension = 3;
>     
>       typedef itk::Image< PixelType, Dimension >   ImageType;
> 
>       typedef itk::ImageFileReader< ImageType >  ReaderType;
> 
>       ReaderType::Pointer reader = ReaderType::New();
> 
>       const char * filename = argv[1];
>       reader->SetFileName( filename );
> 
>       reader->Update();
> 
>       ImageType::Pointer image = reader->GetOutput();
>       return 0;
>     }
> 
> But I'm having a run time error at "reader->Update()":
> 
>       Abort trap
> 
> Could someone please point me what am I doing wrong ?
> Thanks,
> 
> Lucas
> 
> 
> Lucas Lorenzo
> 
> University of Utah
> Nora Eccles Harrison CardioVascular Research and Training Institute
> Fellows Room
> 95 South 2000 East
> Salt Lake City, UT 84112-5000
> 
> e-mail:  lucas at cvrti . utah . edu
> telephone: 801-587-9536
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>