<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">I am trying to read in a raw data file (via MetaImage reader). It's skipping the first byte of my file.</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">The file, according to xxd -b <file> | less</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<div style="margin-left: 40px; font-family: courier new,monospace;">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></div><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">The code:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><div style="margin-left: 40px; font-family: courier new,monospace;">#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 " << v << " and has index " << i << nl;<br>
}<br><br> return 0;<br>}<br></div><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">The output:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><div style="margin-left: 40px; font-family: courier new,monospace;">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><span style="font-family: courier new,monospace;">Value of (9,0,0) is 1024 and has index [7, 0, 0]</span><br style="font-family: courier new,monospace;">
</div><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Looks like the first byte of the file is being skipped. Is this an error or a feature?</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">KLN</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">---------</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Kevin Neff, Ph.D.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Mayo Clinic College of Medicine</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Rochester, MN</span><br style="font-family: courier new,monospace;">
<br><br style="font-family: courier new,monospace;"><br>