[Insight-users] Read .raw MR image file and convert to vtk

Dan Mueller d.mueller at qut.edu.au
Wed May 24 02:33:26 EDT 2006


Hi Mafalda,

The ITK Software Guide strong discourages the use of RAW file formats (see section "Using ImageIO Classes Explicitly").

Instead it suggests the use of Meta images. These are RAW files with an additional header file (extension MHD) which describes the RAW file. An example is as follows:
--- START TEST.MHD ---
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
ElementSpacing = 0.5 0.5 0.5
DimSize = 256 256 256
AnatomicalOrientation = ???
ElementType = MET_UCHAR
ElementDataFile = test.raw
--- END TEST.MHD ---

The RAW file test.raw has 3 dimensions, size=[256, 256, 256], image spacing=[0.5, 0.5, 0.5], and pixels represented by unsigned chars.

If you have an existing RAW file, it is best to create a meta header file which describes this data (size, spacing, pixel type, orientation, etc). Once you have created your Meta header, it is easy to read this into ITK - the factory-based IO classes take care of nearly everything for you!! All you need to do is create an itk::ImageFileReader and point this to the MHD file (see code snippet below):

//NOTE: make sure ImageType is the same type as your MHD file
typedef itk::Image<unsigned char, 3> ImageType;
typedef itk::ImageFileReader<ImageType>	ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("test.mhd");
reader->Update();

For more information about the MetaImage library visit the ITK data website (http://www.itk.org/HTML/Data.htm) or the UNC CADDLab MetaIO website (caddlab.rad.unc.edu/software/MetaIO/MetaIO-Introduction.htm). (The CADDLab page seems to be down at the moment - don't know if that's my end or theirs - but I managed to accessed some it through Google's cache. Just do a google search on "metaimage caddlab" and click on the relevant cached pages.)

Hope this helps.

Cheers

Dan


---- Original message ----
>Date: Wed, 24 May 2006 09:50:20 +0800
>From: "SCHMID, Jerome" <jeromeschmid at surgery.cuhk.edu.hk>  
>Subject: RE: [Insight-users] Read .raw MR image file and convert to vtk  
>To: "Mafalda Sousa" <mmvpgs at gmail.com>, <Insight-users at itk.org>
>
>   Hi,
>
>    
>
>   I don't know the exact encoding of .raw file but I
>   suppose that there are simply the raw data written
>   on binary format on disk. In that case you can use
>   the ImportImageFilter to which you will pass the raw
>   data directly and set by yourself the useful info
>   such as size, spacing and origin. Maybe you can find
>   this in another file. To get the raw data from disk
>   in memory use a standard fstream reading.
>
>    
>
>   Hope this helps.
>
>    
>
>   Best Regards,
>
>    
>
>   Jerome Schmid
>
>    
>
>   ----------------------------------------------------
>
>   From:
>   insight-users-bounces+jeromeschmid=surgery.cuhk.edu.hk at itk.org
>   [mailto:insight-users-bounces+jeromeschmid=surgery.cuhk.edu.hk at itk.org]
>   On Behalf Of Mafalda Sousa
>   Sent: Tuesday, May 23, 2006 10:53 PM
>   To: Insight-users at itk.org
>   Subject: [Insight-users] Read .raw MR image file and
>   convert to vtk
>
>    
>
>   Hello,
>
>    
>
>   I would like to know if it's possible to read .raw
>   image files with ITK. I've tried with RawImageIO and
>   it didn't work.
>
>   Instead of .raw files I also have MINC files. This
>   files are Simulated Brain MR Images obtained from
>   Brainweb http://www.bic.mni.mcgill.ca/brainweb/  .
>
>   I usually use real Dicom files and transform them to
>   VTK files, but this simulated data sets would be
>   very usefull if i could use them. I just don't know
>   how to read them.
>
>    
>
>   Thanks
>
>    
>
>   Mafalda
>________________
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list