[Insight-users] Reading/Writing Metaheader (.mhd) File with RGB Raw (.raw) File

Young-Seok Kim ykim5forward at yahoo.com
Thu Oct 4 12:14:29 EDT 2007


Hi all,
   
  I am having problem in reading/writing a metaheader file (.mhd + .raw). The raw file is an original visible human slice image in RGB.  I wrote the metaheader file myself (see below), and wanted to read .raw file thru it.  I tested with a PNG file for the same slice, so that I can easily compare the result.  What I want is to confirm compatiblity between image file types (.mhd to .mhd, .mhd to .png, and vice versa).
   
  Here is what happened:
  - .png to .png : worked just fine - it produced the same RGB color image.
  - .mhd to .png : produced strange result - there are nine(3x3) B/W image blocks in the same size of the image.
   
  Q1: Anything wrong with my code? My meta file and code are shown below.
  Q2: Is there any free image viewer for both 2D and 3D .mhd file? 
  Or recommentations for each type separately?
   
  Thanks in advance,
  Young.
   
  < Meta file >
  ObjectType = Image
NDims = 2
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 1
Offset = 0 0
CenterOfRotation = 0 0
ElementSpacing = 1 1
DimSize = 2048 1216
AnatomicalOrientation = ??
ElementNumberOfChannels = 3
ElementType = MET_UCHAR
ElementDataFile = a_vm1150.raw
   
  < Code for Reading-Writing >
  typedef itk::RGBPixel< unsigned char > RGBPixelType;
  typedef itk::Image< RGBPixelType, 2 > RGBImageType;
  typedef itk::ImageFileReader< RGBImageType > RGBReaderType;
  typedef itk::ImageFileWriter< RGBImageType > RGBWriterType;
   
  RGBImageType::Pointer image = RGBImageType::New();
  RGBReaderType::Pointer reader = RGBReaderType::New();
  RGBWriterType::Pointer writer = RGBWriterType::New();
  reader->SetFileName("C:\\a_vm1150.mhd");
  writer->SetFileName("C:\\a_vm1150_out.png");
   
  writer->SetInput(reader->GetOutput());
  writer->Update();
   
  --- End of message ---
   
   

       
---------------------------------
Pinpoint customers who are looking for what you sell. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071004/0856b89e/attachment.html


More information about the Insight-users mailing list