Dan,<br><br>After looking at the header, I realized that it could be a byte-order issue. Changing it to True did the trick.<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">NDims = 3</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">DimSize = 1388 560 48</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ElementSpacing = 1.29 1.29 5.44</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Position = 0 0 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ElementByteOrderMSB = False</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">ElementType = MET_USHORT</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ElementDataFile = img8.raw</span><br style="font-family: courier new,monospace;">
</div>
<br style="font-family: courier new,monospace;">
Thanks,<br><br>KLN<br><br><br><br><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><br><div class="gmail_quote">On Thu, Nov 18, 2010 at 11:52 PM, Dan Mueller <span dir="ltr"><<a href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Kevin,<br>
<br>
Please post the Meta Header (*.mhd) file corresponding to the raw<br>
file. The header can skip leading bytes by specifying HeaderSize. See<br>
here:<br>
<a href="http://www.itk.org/Wiki/MetaIO/Documentation" target="_blank">http://www.itk.org/Wiki/MetaIO/Documentation</a><br>
<a href="http://www.itk.org/Wiki/images/2/27/MetaIO-Introduction.pdf" target="_blank">http://www.itk.org/Wiki/images/2/27/MetaIO-Introduction.pdf</a><br>
<br>
Cheers, Dan<br>
<div><div></div><div class="h5"><br>
On 18 November 2010 22:25, Kevin Neff <<a href="mailto:kevin.l.neff@gmail.com">kevin.l.neff@gmail.com</a>> wrote:<br>
><br>
> I am trying to read in a raw data file (via MetaImage reader). It's<br>
> skipping the first byte of my file.<br>
><br>
> The file, according to xxd -b <file> | less<br>
><br>
> 0000000: 00000000 00001001 00000000 00000110 00000000 00001010 ......<br>
> 0000006: 00000000 00000101 00000000 00000101 00000000 00000110 ......<br>
> 000000c: 00000000 00000000 00000000 00000100 00000000 00000100 ......<br>
> 0000012: 00000000 00001001 00000000 00000011 00000000 00000100 ......<br>
><br>
> The code:<br>
><br>
> #include <iostream><br>
> #include "itkImage.h"<br>
> #include "itkImageFileReader.h"<br>
> #include "itkImageFileWriter.h"<br>
> //#include "itkRawImageIO.h"<br>
> #include "itkMetaImageIO.h"<br>
><br>
> #define print std::cout<br>
> #define nl std::endl<br>
><br>
> int main( int argc, char** argv )<br>
> {<br>
> typedef itk::Image< unsigned short, 3 > ImageType;<br>
><br>
> ImageType::Pointer image = ImageType::New();<br>
><br>
> ImageType::IndexType start;<br>
> start[0] = 0; // first index on X<br>
> start[1] = 0; // first index on Y<br>
> start[2] = 0; // first index on Z<br>
><br>
> ImageType::SizeType size;<br>
> size[0] = 1388; // size along X<br>
> size[1] = 560; // size along Y<br>
> size[2] = 48; // size along Z<br>
><br>
> ImageType::RegionType region;<br>
> region.SetSize( size );<br>
> region.SetIndex( start );<br>
> image->SetRegions( region );<br>
><br>
> image->Allocate();<br>
><br>
> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
> typedef itk::MetaImageIO ImageIOType;<br>
><br>
> ImageIOType::Pointer MIIO = ImageIOType::New();<br>
><br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> const char * infile = argv[1];<br>
> reader->SetFileName( infile );<br>
> image = reader->GetOutput();<br>
><br>
> print << "Reading from file (" << argv[0] << ")" << nl;<br>
> try{ reader->Update(); }<br>
> catch( itk::ExceptionObject & err ) {<br>
> std::cerr << "ExceptionObject caught! Check filename" << std::endl;<br>
> std::cerr << err << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
><br>
> const ImageType::SpacingType& sp = image->GetSpacing();<br>
> print << "Spacing = ";<br>
> print << sp[0] << ", " << sp[1] << ", " << sp[2] << std::endl;<br>
><br>
> const ImageType::PointType& orgn = image->GetOrigin();<br>
> std::cout << "Origin = ";<br>
> std::cout << orgn[0] << ", " << orgn[1] << ", " << orgn[2] << std::endl;<br>
><br>
> typedef itk::Point< double, ImageType::ImageDimension > PointType;<br>
><br>
> PointType p;<br>
> ImageType::IndexType i;<br>
> ImageType::PixelType v;<br>
> for( int x = 0; x < 10; x += 1 ) {<br>
> p[0] = x; p[1] = 0; p[2] = 0;<br>
> image->TransformPhysicalPointToIndex(p,i);<br>
> v = image->GetPixel( i );<br>
> print << "Value of (" << p[0] << "," << p[1] << "," << p[2] << ") is "<br>
> << v << " and has index " << i << nl;<br>
> }<br>
><br>
> return 0;<br>
> }<br>
><br>
> The output:<br>
><br>
><br>
> tukey # make && ./register img8.mhd<br>
> Scanning dependencies of target register<br>
> [100%] Building CXX object CMakeFiles/register.dir/main.cxx.o<br>
> Linking CXX executable register<br>
> [100%] Built target register<br>
> Reading from file (./register)<br>
> Spacing = 1.29, 1.29, 5.44<br>
> Origin = 0, 0, 0<br>
> Value of (0,0,0) is 2304 and has index [0, 0, 0]<br>
> Value of (1,0,0) is 1536 and has index [1, 0, 0]<br>
> Value of (2,0,0) is 2560 and has index [2, 0, 0]<br>
> Value of (3,0,0) is 2560 and has index [2, 0, 0]<br>
> Value of (4,0,0) is 1280 and has index [3, 0, 0]<br>
> Value of (5,0,0) is 1280 and has index [4, 0, 0]<br>
> Value of (6,0,0) is 1536 and has index [5, 0, 0]<br>
> Value of (7,0,0) is 1536 and has index [5, 0, 0]<br>
> Value of (8,0,0) is 0 and has index [6, 0, 0]<br>
> Value of (9,0,0) is 1024 and has index [7, 0, 0]<br>
><br>
> Looks like the first byte of the file is being skipped. Is this an error or<br>
> a feature?<br>
><br>
> KLN<br>
><br>
><br>
> ---------<br>
> Kevin Neff, Ph.D.<br>
> Mayo Clinic College of Medicine<br>
> Rochester, MN<br>
</div></div></blockquote></div><br>