[ITK Community] RawImageIO volume writing

Emiliano Pastorelli emiliano.pastorelli at gmail.com
Tue Mar 18 10:49:00 EDT 2014


Thanks all, you avoided me a strong headache!

Somehow i thought that the order on which the data was written in the 
raw file  depended from the parameters i was giving to the RawImageIO. 
(i had a template of nhdr file that i was using with the .raw image for 
the testing).

Now I just output the nhdr as Bradley suggested and it works smoothly 
now, sorry for the dumb approach i had!

Best,
Emiliano

Il 18/03/14 15:58, Luis Ibanez ha scritto:
> Hi Emiliano,
>
> Please note that the RawImageIO class will throw away all the Image 
> Metadata.
>
> RawImageIO only stores the byte data corresponding to pixel intensity 
> values.
>
> The rest:  direction, spacing, origin...etc..  is dismissed.
>
> In practice, there is no real advantage in using the RawImageIO.
>
> You may want to rather use the MetaImageIO format,
> and get two files:
>
> .mhd with a text header
> .raw with the raw byte data for the pixel intensities.
>
>
> Hope this helps,
>
>     Luis
>
>
>
> On Tue, Mar 18, 2014 at 9:49 AM, Emiliano Pastorelli 
> <emiliano.pastorelli at gmail.com <mailto:emiliano.pastorelli at gmail.com>> 
> wrote:
>
>     Hi Matt,
>
>     is the way I use the RawImageIO together with the image writer
>     correct?
>     I'm still trying to change directions, swapping them, playing
>     around with some other values, and it just keeps on producing the
>     same wrong output (i'm sure the raw image is newly generated
>     though and i'm loading that one in paraview to visualize the
>     results or in my software to analze it).
>     I start wondering because nothing i do seems to cause real
>     changes, so i think i might be misusing the whole thing, but i
>     don't get how.
>
>     Thanks and Best,
>     Emiliano
>
>     Il 18/03/14 15:24, Matt McCormick ha scritto:
>>     Hi Emiliano,
>>
>>     I am not sure I see the issue.  Is the image missing the correct
>>     spacing information?
>>
>>     Matt
>>
>>
>>     On Tue, Mar 18, 2014 at 8:32 AM, Emiliano Pastorelli
>>     <emiliano.pastorelli at gmail.com
>>     <mailto:emiliano.pastorelli at gmail.com>> wrote:
>>
>>         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
>>
>>         _______________________________________________
>>         Community mailing list
>>         Community at itk.org <mailto:Community at itk.org>
>>         http://public.kitware.com/cgi-bin/mailman/listinfo/community
>>
>>
>
>
>     _______________________________________________
>     Community mailing list
>     Community at itk.org <mailto:Community at itk.org>
>     http://public.kitware.com/cgi-bin/mailman/listinfo/community
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140318/6fe0274e/attachment-0002.html>


More information about the Community mailing list