<div dir="ltr">Hi Mark,<br><br>I wonder whether you can use vtkImageToImageFilter to hold the image data from the exporter.<br><br>Any way I use the <span style=" color:#008000;">itkVTKImageToImageFilter to do the conversion and it works well for me.<br>
<br>Here is the snippet<br><br><br></span><span style=" color:#c0c0c0;"> </span><font size="4"><span style="color: rgb(128, 128, 0);">typedef</span><span style="color: rgb(192, 192, 192);"> </span>itk<span style="color: rgb(0, 0, 0);">::</span>Image<span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(128, 128, 0);">unsigned</span><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 128, 0);">int</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 128);">3</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(192, 192, 192);"> </span>ImageType<span style="color: rgb(0, 0, 0);">;</span>
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);">     </span><span style="color: rgb(128, 128, 0);">typedef</span><span style="color: rgb(192, 192, 192);"> </span>itk<span style="color: rgb(0, 0, 0);">::</span>VTKImageToImageFilter<span style="color: rgb(0, 0, 0);">&lt;</span>ImageType<span style="color: rgb(0, 0, 0);">&gt;</span>VTKImageToImageType<span style="color: rgb(0, 0, 0);">;</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);">     </span>VTKImageToImageType<span style="color: rgb(0, 0, 0);">::</span>Pointer<span style="color: rgb(192, 192, 192);"> </span>converter<span style="color: rgb(0, 0, 0);">=</span>VTKImageToImageType<span style="color: rgb(0, 0, 0);">::</span>New<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);">     </span>converter<span style="color: rgb(0, 0, 0);">-&gt;</span>SetInput<span style="color: rgb(0, 0, 0);">(</span>stencil2<span style="color: rgb(0, 0, 0);">-&gt;</span>GetOutput<span style="color: rgb(0, 0, 0);">());</span></font></pre>
<font size="4">
</font><pre style="margin: 0px; text-indent: 0px;"><font size="4"><span style="color: rgb(192, 192, 192);">     </span>converter<span style="color: rgb(0, 0, 0);">-&gt;</span>Update<span style="color: rgb(0, 0, 0);">();</span></font></pre>
<br><br><br><div class="gmail_quote">On Tue, Sep 20, 2011 at 5:59 AM, Mark Roden <span dir="ltr">&lt;<a href="mailto:mmroden@gmail.com">mmroden@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br>
<br>
I&#39;ve looked on google and the various newsgroups and have not found<br>
the answer to what I thought was a pretty straightforward question.<br>
<br>
I have a vtkImageData object that has been obtained... somehow.  I do<br>
not have the pipeline at this point, just the output.  The user could<br>
have done any number of things to have arrived at this point, and so I<br>
store a vtkImageData that has been DeepCopied off of the end of<br>
whatever pipeline was employed.<br>
<br>
I then want to save that image in the Analyze format.  A coworker made<br>
his own reader/writer using the information that Mayo put out, but the<br>
resulting files don&#39;t appear to be oriented correctly.  I want to<br>
verify if his version is producing a bug, and I wanted to use the itk<br>
version of the writing plugin to do the work.<br>
<br>
Here&#39;s what I have:<br>
<br>
#ifdef ITK_IMG_WRITER<br>
#include &quot;vtkImageExport.h&quot;<br>
#include &lt;itkVTKImageImport.h&gt;<br>
#include &quot;itkImageFileWriter.h&quot;<br>
#include &quot;itkAnalyzeImageIO.h&quot;<br>
#include &quot;itkImage.h&quot;<br>
#include &quot;itkOrientedImage.h&quot;<br>
#endif<br>
<br>
<br>
void saveAnalyzeImage(vtkImageData * const image, const QString &amp;file) {<br>
<br>
#ifdef ITK_IMG_WRITER<br>
    //this code is done using ITK, and so requires that ITK be included<br>
    typedef itk::OrientedImage&lt; signed short, 3 &gt; CTImage;<br>
    typedef itk::ImageFileWriter&lt; CTImage&gt; CTWriter;<br>
    typedef itk::VTKImageImport&lt;CTImage&gt; VTKImageImportType;<br>
<br>
    CTWriter::Pointer theWriter = CTWriter::New();<br>
<br>
    theWriter-&gt;SetFileName(file.toStdString().c_str());<br>
<br>
    vtkImageExport* theExporter = vtkImageExport::New();<br>
    theExporter-&gt;SetInput(image);<br>
<br>
    VTKImageImportType::Pointer vtkImageToImageFilter =<br>
VTKImageImportType::New();<br>
    theExporter-&gt;SetOutput(vtkImageToImageFilter);<br>
    vtkImageToImageFilter-&gt;Update();<br>
<br>
    theWriter-&gt;SetInput(vtkImageToImageFilter-&gt;GetOutput());<br>
<br>
    itk::AnalyzeImageIO::Pointer analyzeIO = itk::AnalyzeImageIO::New();<br>
    theWriter-&gt;SetImageIO(analyzeIO);<br>
<br>
    try {<br>
        theWriter-&gt;Update();<br>
    } catch(itk::ExceptionObject ex){<br>
        return; //do something else here for error handling<br>
    }<br>
    theWriter-&gt;Delete();<br>
    vtkImageToImageFilter-&gt;Delete();<br>
    analyzeIO-&gt;Delete();<br>
    return;<br>
<br>
#else<br>
    //do the other code instead<br>
#endif<br>
}<br>
<br>
This code is not compiling, because<br>
theExporter-&gt;SetOutput(vtkImageToImageFilter) doesn&#39;t work.  I&#39;ve also<br>
tried just using the VTKImageImportType object directly, but that does<br>
not have a SetInput method.  As could be guessed from the code, I also<br>
tried vtkImageToImageFilter, but that appears to be a deprecated<br>
leftover from 2004 or so.  Unless there&#39;s some include file I&#39;m not<br>
finding?<br>
<br>
All I really want is for vtk to read and write analyze files.  Barring<br>
that, I want to be able to seamlessly convert from a vtkImageData<br>
object to an itk::Image object so I can use itk&#39;s analyze export and<br>
importing functions.  How can I fix that code to make it work?<br>
<br>
Thanks,<br>
Mark<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Jothybasu K Selvaraj<br>PhD Student<br>University of Liverpool<br>Liverpool,UK<br></div><br>
</div>