<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Emiliano,<div><br></div><div>In your initial description you didn't indicate that you were trying to change the order of the axis.</div><div><br></div><div>The RawImageIO does not write out the Spacing,Orientation,byte order,size, etc, it just rights out the image buffer as raw. When writing those have not effect, they are however required when writing.</div><div><br></div><div>Why not just write it out as an nhdr file directly?</div><div><br></div><div>In SimpleITK I can just do:</div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="color: #5330e1">In [<b>9</b>]: </span>sitk.WriteImage(sitk.Image(120,120,120,sitk.sitkUInt16), "img.nhdr")</div></div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><span style="color: #5330e1">In [<b>10</b>]: </span>cat img.nhdr</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"><div style="margin: 0px;">NRRD0004</div><div style="margin: 0px;"># Complete NRRD file format specification at:</div><div style="margin: 0px;"># <a href="http://teem.sourceforge.net/nrrd/format.html">http://teem.sourceforge.net/nrrd/format.html</a></div><div style="margin: 0px;">type: unsigned short</div><div style="margin: 0px;">dimension: 3</div><div style="margin: 0px;">space: left-posterior-superior</div><div style="margin: 0px;">sizes: 120 120 120</div><div style="margin: 0px;">space directions: (1,0,0) (0,1,0) (0,0,1)</div><div style="margin: 0px;">kinds: domain domain domain</div><div style="margin: 0px;">endian: little</div><div style="margin: 0px;">encoding: raw</div><div style="margin: 0px;">space origin: (0,0,0)</div><div style="margin: 0px;">data file: img.raw</div><div style="margin: 0px;"><br></div></div><div>And the img.raw file is right there.</div><div><br></div><div>Hope that helps.</div><div>Brad</div><div><br><div><div>On Mar 18, 2014, at 9:49 AM, Emiliano Pastorelli <<a href="mailto:emiliano.pastorelli@gmail.com">emiliano.pastorelli@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Matt,<br>
      <br>
      is the way I use the RawImageIO together with the image writer
      correct?<br>
      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).<br>
      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.<br>
      <br>
      Thanks and Best,<br>
      Emiliano<br>
      <br>
      Il 18/03/14 15:24, Matt McCormick ha scritto:<br>
    </div>
    <blockquote cite="mid:CALzTN-S8rxnv-y7-NzsSSp96LFdMjwy6DaNj_61-=vzMaLuN2w@mail.gmail.com" type="cite">
      <div dir="ltr">Hi Emiliano,
        <div><br>
        </div>
        <div>I am not sure I see the issue.  Is the image missing the
          correct spacing information?</div>
        <div><br>
        </div>
        <div>Matt</div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">
          On Tue, Mar 18, 2014 at 8:32 AM, Emiliano Pastorelli <span dir="ltr"><<a moz-do-not-send="true" href="mailto:emiliano.pastorelli@gmail.com" target="_blank">emiliano.pastorelli@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">
              <div>
                <div>
                  <div>
                    <div>
                      <div>Hi all,<br>
                        <br>
                      </div>
                      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).<br>
                      <br>
                    </div>
                    the look of a nhdr header that i was loading in my
                    software is this  :<br>
                    #################################<br>
                    NRRD0004<br>
                    # Complete NRRD file format specification at:<br>
                    # <a moz-do-not-send="true" href="http://teem.sourceforge.net/nrrd/format.html" target="_blank">http://teem.sourceforge.net/nrrd/format.html</a><br>
                    type: short<br>
                    dimension: 3<br>
                    space: left-posterior-superior<br>
                    sizes: 795 788 576<br>
                    space directions: (1,0,0) (0,1,0) (0,0,1)<br>
                    kinds: domain domain domain<br>
                    endian: little<br>
                    encoding: raw<br>
                    space origin: (-397,-393.5,-287.5)<br>
                    data file: 4a.raw<br>
                    #################################<br>
                    <br>
                  </div>
                  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. <br>
                  <br>
                </div>
                A topdown view of the volume as it should look like<br>
                <a moz-do-not-send="true" href="http://www.kyb3.org/images/MhdRaw.png" target="_blank">http://www.kyb3.org/images/MhdRaw.png</a><br>
              </div>
              A topdown of how it looks like<br>
              <a moz-do-not-send="true" href="http://www.kyb3.org/images/NhdrRaw.png" target="_blank">http://www.kyb3.org/images/NhdrRaw.png</a><br>
              <div>
                <div>
                  <div><br>
                    #################################<br>
                    typedef RawImageIO<short, 3> rawWriter;<br>
                        rawWriter::Pointer newRawWriter =
                    rawWriter::New();<br>
                        newRawWriter->SetFileTypeToBinary();<br>
                    <br>
                        newRawWriter->SetDimensions(0,150);<br>
                        newRawWriter->SetDimensions(1,150);<br>
                        newRawWriter->SetDimensions(2,150);<br>
                    <br>
                        vector<double> dirX(3);<br>
                        dirX[0]=1.0;dirX[1]=0.0;dirX[2]=0.0;<br>
                        vector<double> dirZ(3);<br>
                        dirZ[0]=0.0;dirZ[1]=0.0;dirZ[2]=1.0;<br>
                        vector<double> dirY(3);<br>
                        dirY[0]=0.0;dirY[1]=1.0;dirY[2]=0.0;<br>
                    <br>
                        newRawWriter->SetDirection(0,dirX);<br>
                        newRawWriter->SetDirection(1,dirZ);<br>
                        newRawWriter->SetDirection(2,dirY);<br>
                        newRawWriter->SetSpacing(0,1);<br>
                        newRawWriter->SetSpacing(1,1);<br>
                        newRawWriter->SetSpacing(2,1);<br>
                    <br>
                        newRawWriter->SetHeaderSize(0);<br>
                        newRawWriter->SetByteOrderToLittleEndian();<br>
                        newRawWriter->SetNumberOfComponents(1);<br>
                    <br>
                        /*<br>
                         * SAVE TO FILE<br>
                         */<br>
                        typedef itk::ImageFileWriter< OutputImageType
                    > WriterType;<br>
                        WriterType::Pointer writer = WriterType::New();<br>
                        writer->SetInput(
                    LabelToBinary->GetOutput() );<br>
                        writer->SetImageIO(newRawWriter);<br>
                        writer->SetFileName(
                    "../VolumeAnalysis/Frangi.raw" );<br>
                    <br>
                        try{<br>
                            writer->Update();<br>
                        }<br>
                        catch( itk::ExceptionObject & error ){<br>
                            std::cerr << "Error: " << error
                    << std::endl;<br>
                            return EXIT_FAILURE;<br>
                        }<br>
                    <br>
                        cout << "Volume Saved" << endl;<br>
                    #################################<br>
                    <br>
                  </div>
                  <div>Best,<br>
                  </div>
                  <div>Emiliano<br>
                  </div>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            Community mailing list<br>
            <a moz-do-not-send="true" href="mailto:Community@itk.org">Community@itk.org</a><br>
            <a moz-do-not-send="true" href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>Community mailing list<br><a href="mailto:Community@itk.org">Community@itk.org</a><br>http://public.kitware.com/cgi-bin/mailman/listinfo/community<br></blockquote></div><br></div></body></html>