[Insight-users] Convert VTK image to ITK image
Karl Diedrich
karl.diedrich at azeresearch.com
Wed Feb 1 15:08:29 EST 2012
Hi Felix,
I am using ITK 3.20.0 and itk::VTKImageToImageFilter was from the latest
Slicer 4.0 source code.
I was just able to convert a VTK image to ITK with this template function
without using the itk::VTKImageToImageFilter .
IMAGEDATATYPE = short and DIMENSIONS = 3
typename itk::Image<IMAGEDATATYPE, DIMENSIONS>::Pointer
convertVtkToItk(vtkImageData* vtkInput)
{
typedef itk::Image<IMAGEDATATYPE, DIMENSIONS> InputImageType;
typedef itk::VTKImageImport<InputImageType> InputImageImportType;
vtkSmartPointer<vtkImageExport> inputImageExporter =
vtkImageExport::New();
inputImageExporter->SetInput(vtkInput);
typename InputImageImportType::Pointer inputImageImporter =
InputImageImportType::New();
ConnectPipelines(inputImageExporter.GetPointer(),
inputImageImporter);
typename InputImageType::Pointer outputImage =
const_cast<InputImageType*>(inputImageImporter->GetOutput());
outputImage->Update();
if(outputImage.IsNull())
{
QLOG_WARN() << "ITK image is invalid.";
}
return outputImage;
}
Cheers,
On Wed, Feb 1, 2012 at 2:34 PM, Félix C. Morency <felix.morency at gmail.com>wrote:
> Karl,
>
> Try double instead of float in your image type.
>
> Also, could you tell me what version of ITK you are using?
>
> Thanks,
> -Félix
>
> On Wed, Feb 1, 2012 at 1:53 PM, Karl Diedrich
> <karl.diedrich at azeresearch.com> wrote:
> > Hello,
> >
> > I am trying to use itk::VTKImageToImageFilter to to convert a VTK image
> to
> > an ITK image.
> > The call vtkImageToImageFilter->Update(); never returns but there is no
> > error message and program simply stops.
> >
> > vtkImageData* vtkInput;
> >
> >
> > typedef itk::Image<float, 3> ImageType;
> >
> > typedef itk::VTKImageToImageFilter<ImageType>
> VTKImageToImageType;
> >
> > typename VTKImageToImageType::Pointer vtkImageToImageFilter =
> > VTKImageToImageType::New();
> > QLOG_DEBUG() << "Prepared Filter";
> > vtkImageToImageFilter->SetInput(vtkInput);
> > QLOG_DEBUG() << "Set input to filter";
> > vtkImageToImageFilter->Update();
> > QLOG_DEBUG() << "Updated filter";
> > typename ImageType::ConstPointer itkOutput =
> > vtkImageToImageFilter->GetOutput();
> > QLOG_DEBUG() << "Got output";
> >
> >
> >
> >
> > --
> > Karl Diedrich, Ph.D.
> > Principal Engineer
> > ----------------------------------------
> > AZE Research and Development
> > 1 Broadway, 14th floor
> > Cambridge, MA 02142
> > Tel: +1 (617) 475-1502
> > Cell: +1 (801) 350-1251
> > www.azeofamerica.com
> >
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>
>
>
> --
> --
> Félix C. Morency, M.Sc.
> Plateforme d’analyse et de visualisation d’images
> Centre Hospitalier Universitaire de Sherbrooke
> Centre de recherche clinique Étienne-Le Bel
> Local Z5-3031 | 819.346.1110 ext 16634
>
--
Karl Diedrich, Ph.D.
Principal Engineer
----------------------------------------
AZE Research and Development
1 Broadway, 14th floor
Cambridge, MA 02142
Tel: +1 (617) 475-1502
Cell: +1 (801) 350-1251
www.azeofamerica.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120201/126977a8/attachment.htm>
More information about the Insight-users
mailing list