[Insight-users] MetaImage Read Problem

Kevin Neff kevin.l.neff at gmail.com
Fri Nov 19 10:30:28 EST 2010


Dan,

After looking at the header, I realized that it could be a byte-order
issue.  Changing it to True did the trick.

NDims = 3
DimSize = 1388 560 48
ElementSpacing = 1.29 1.29 5.44
Position = 0 0 0
ElementByteOrderMSB = False
ElementType = MET_USHORT
ElementDataFile = img8.raw

Thanks,

KLN





On Thu, Nov 18, 2010 at 11:52 PM, Dan Mueller <dan.muel at gmail.com> wrote:

> Hi Kevin,
>
> Please post the Meta Header (*.mhd) file corresponding to the raw
> file. The header can skip leading bytes by specifying HeaderSize. See
> here:
>    http://www.itk.org/Wiki/MetaIO/Documentation
>    http://www.itk.org/Wiki/images/2/27/MetaIO-Introduction.pdf
>
> Cheers, Dan
>
> On 18 November 2010 22:25, Kevin Neff <kevin.l.neff at gmail.com> wrote:
> >
> > I am trying to read in a raw data file (via MetaImage reader).  It's
> > skipping the first byte of my file.
> >
> > The file, according to xxd -b <file> | less
> >
> > 0000000: 00000000 00001001 00000000 00000110 00000000 00001010  ......
> > 0000006: 00000000 00000101 00000000 00000101 00000000 00000110  ......
> > 000000c: 00000000 00000000 00000000 00000100 00000000 00000100  ......
> > 0000012: 00000000 00001001 00000000 00000011 00000000 00000100  ......
> >
> > The code:
> >
> > #include <iostream>
> > #include "itkImage.h"
> > #include "itkImageFileReader.h"
> > #include "itkImageFileWriter.h"
> > //#include "itkRawImageIO.h"
> > #include "itkMetaImageIO.h"
> >
> > #define print std::cout
> > #define nl    std::endl
> >
> > int main( int argc, char** argv )
> > {
> >   typedef itk::Image< unsigned short, 3 > ImageType;
> >
> >   ImageType::Pointer image = ImageType::New();
> >
> >   ImageType::IndexType start;
> >   start[0] =   0;  // first index on X
> >   start[1] =   0;  // first index on Y
> >   start[2] =   0;  // first index on Z
> >
> >   ImageType::SizeType  size;
> >   size[0]  = 1388;  // size along X
> >   size[1]  =  560;  // size along Y
> >   size[2]  =   48;  // size along Z
> >
> >   ImageType::RegionType region;
> >   region.SetSize( size );
> >   region.SetIndex( start );
> >   image->SetRegions( region );
> >
> >   image->Allocate();
> >
> >   typedef itk::ImageFileReader< ImageType > ReaderType;
> >   typedef itk::ImageFileWriter< ImageType > WriterType;
> >   typedef itk::MetaImageIO                  ImageIOType;
> >
> >   ImageIOType::Pointer MIIO = ImageIOType::New();
> >
> >   ReaderType::Pointer reader = ReaderType::New();
> >   const char * infile = argv[1];
> >   reader->SetFileName( infile );
> >   image = reader->GetOutput();
> >
> >   print << "Reading from file (" << argv[0] << ")" << nl;
> >   try{ reader->Update(); }
> >   catch( itk::ExceptionObject & err )    {
> >     std::cerr << "ExceptionObject caught!  Check filename" << std::endl;
> >     std::cerr << err << std::endl;
> >     return EXIT_FAILURE;
> >   }
> >
> >   const ImageType::SpacingType& sp = image->GetSpacing();
> >   print << "Spacing = ";
> >   print << sp[0] << ", " << sp[1] << ", " << sp[2] << std::endl;
> >
> >   const ImageType::PointType& orgn = image->GetOrigin();
> >   std::cout << "Origin = ";
> >   std::cout << orgn[0] << ", " << orgn[1] << ", " << orgn[2] <<
> std::endl;
> >
> >   typedef itk::Point< double, ImageType::ImageDimension > PointType;
> >
> >   PointType p;
> >   ImageType::IndexType i;
> >   ImageType::PixelType v;
> >   for(  int x = 0;  x < 10;  x += 1  )   {
> >     p[0] = x; p[1] = 0; p[2] = 0;
> >     image->TransformPhysicalPointToIndex(p,i);
> >     v = image->GetPixel( i );
> >     print << "Value of (" << p[0] << "," << p[1] << "," << p[2] << ") is
> "
> > << v << " and has index " << i << nl;
> >   }
> >
> >   return 0;
> > }
> >
> > The output:
> >
> >
> > tukey # make && ./register img8.mhd
> > Scanning dependencies of target register
> > [100%] Building CXX object CMakeFiles/register.dir/main.cxx.o
> > Linking CXX executable register
> > [100%] Built target register
> > Reading from file (./register)
> > Spacing = 1.29, 1.29, 5.44
> > Origin = 0, 0, 0
> > Value of (0,0,0) is 2304 and has index [0, 0, 0]
> > Value of (1,0,0) is 1536 and has index [1, 0, 0]
> > Value of (2,0,0) is 2560 and has index [2, 0, 0]
> > Value of (3,0,0) is 2560 and has index [2, 0, 0]
> > Value of (4,0,0) is 1280 and has index [3, 0, 0]
> > Value of (5,0,0) is 1280 and has index [4, 0, 0]
> > Value of (6,0,0) is 1536 and has index [5, 0, 0]
> > Value of (7,0,0) is 1536 and has index [5, 0, 0]
> > Value of (8,0,0) is 0 and has index [6, 0, 0]
> > Value of (9,0,0) is 1024 and has index [7, 0, 0]
> >
> > Looks like the first byte of the file is being skipped.  Is this an error
> or
> > a feature?
> >
> > KLN
> >
> >
> > ---------
> > Kevin Neff, Ph.D.
> > Mayo Clinic College of Medicine
> > Rochester, MN
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101119/af68f4e6/attachment.htm>


More information about the Insight-users mailing list