[ITK Community] RawImageIO volume writing
Emiliano Pastorelli
emiliano.pastorelli at gmail.com
Tue Mar 18 08:32:16 EDT 2014
Hi all,
I am trying to write to file a processed volume on which i'm working. Due
to the fact that another software of mine that performs another analysis on
the filtered dataset reads in nhdr+raw files (i write manually the nhdr,
and from there i only take size and endianness of the raw data).
the look of a nhdr header that i was loading in my software is this :
#################################
NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: short
dimension: 3
space: left-posterior-superior
sizes: 795 788 576
space directions: (1,0,0) (0,1,0) (0,0,1)
kinds: domain domain domain
endian: little
encoding: raw
space origin: (-397,-393.5,-287.5)
data file: 4a.raw
#################################
what i am trying to do in the code to write a file in a similar format that
my software can understand and read. it's my first attempt at using the
RawImageIO, but doesn't matter what i change, the saved volume it's always
wrongly reconstructed.
A topdown view of the volume as it should look like
http://www.kyb3.org/images/MhdRaw.png
A topdown of how it looks like
http://www.kyb3.org/images/NhdrRaw.png
#################################
typedef RawImageIO<short, 3> rawWriter;
rawWriter::Pointer newRawWriter = rawWriter::New();
newRawWriter->SetFileTypeToBinary();
newRawWriter->SetDimensions(0,150);
newRawWriter->SetDimensions(1,150);
newRawWriter->SetDimensions(2,150);
vector<double> dirX(3);
dirX[0]=1.0;dirX[1]=0.0;dirX[2]=0.0;
vector<double> dirZ(3);
dirZ[0]=0.0;dirZ[1]=0.0;dirZ[2]=1.0;
vector<double> dirY(3);
dirY[0]=0.0;dirY[1]=1.0;dirY[2]=0.0;
newRawWriter->SetDirection(0,dirX);
newRawWriter->SetDirection(1,dirZ);
newRawWriter->SetDirection(2,dirY);
newRawWriter->SetSpacing(0,1);
newRawWriter->SetSpacing(1,1);
newRawWriter->SetSpacing(2,1);
newRawWriter->SetHeaderSize(0);
newRawWriter->SetByteOrderToLittleEndian();
newRawWriter->SetNumberOfComponents(1);
/*
* SAVE TO FILE
*/
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput( LabelToBinary->GetOutput() );
writer->SetImageIO(newRawWriter);
writer->SetFileName( "../VolumeAnalysis/Frangi.raw" );
try{
writer->Update();
}
catch( itk::ExceptionObject & error ){
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
cout << "Volume Saved" << endl;
#################################
Best,
Emiliano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140318/bb780edb/attachment-0001.html>
More information about the Community
mailing list