[vtkusers] converting from vtk to itk and back again

Jothy jothybasu at gmail.com
Tue Sep 20 05:23:17 EDT 2011


Sorry for the incomplete message.

Hi Mark,

I wonder whether you can use vtkImageToImageFilter to hold the image data
from the exporter.

Any way I use the itkVTKImageToImageFilter to do the conversion and it works
well for me.

Here is the snippet


typedef itk::Image<unsigned int,3> ImageType;

     typedef itk::VTKImageToImageFilter<ImageType>VTKImageToImageType;

      VTKImageToImageType::Pointer converter=VTKImageToImageType::New();

      converter->SetInput(imgData);

      converter->Update();

Now you could get the itk image as converter->GetOutput(). I have
attached the src and headers for you.

Jothy




On Tue, Sep 20, 2011 at 10:19 AM, Jothy <jothybasu at gmail.com> wrote:

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


-- 
Jothybasu K Selvaraj
PhD Student
University of Liverpool
Liverpool,UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110920/04eb2664/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itkVTKImageToImageFilter.h
Type: text/x-chdr
Size: 3384 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110920/04eb2664/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itkVTKImageToImageFilter.txx
Type: application/octet-stream
Size: 3217 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110920/04eb2664/attachment.obj>


More information about the vtkusers mailing list