[ITK-users] Convert vtkImageData to an itk::Image

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[ITK-users] Convert vtkImageData to an itk::Image

ITK - Users mailing list
Dear All,

I read some DICOM data using vtkGDCMImageReader, then I change the sapacing and reslice them. Next I want to change that vtk image to itk image to be able to apply noise removal. But as soon as the code reaches the "filter_toitkimage->Update();" line the program just exits without saying anything (actually it says:The program '[14040] QtGuiApplication2.exe' has exited with code 3 (0x3).).

Here is the code:

vtkSmartPointer<vtkGDCMImageReader> reader = vtkSmartPointer<vtkGDCMImageReader>::New();
    reader->SetFileNames(vtkfiles);
    reader->Update();
   
    vtkSmartPointer<vtkImageChangeInformation> changer = vtkSmartPointer<vtkImageChangeInformation>::New();
    changer->SetOutputSpacing(pixlespacing, pixlespacing, ippzspacing);//@majidnow
    changer->SetInputConnection(reader->GetOutputPort());

    vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
    reslice->SetInputConnection(changer->GetOutputPort());
   
    //to change VTK image to ITK image
    const unsigned int Dimension = 3;

    using PixelType = double;
    using ImageType = itk::Image< PixelType, Dimension >;

    using FilterType = itk::VTKImageToImageFilter< ImageType >;
    FilterType::Pointer filter_toitkimage = FilterType::New();
    filter_toitkimage->SetInput(reslice->GetOutput());

    try
    {
        filter_toitkimage->Update();
    }
    catch (itk::ExceptionObject & error)
    {
        std::cerr << "Error: " << error << std::endl;
        //return EXIT_FAILURE;
    }
 

Any idea why this happens?


The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
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.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
https://itk.org/mailman/listinfo/insight-users
Reply | Threaded
Open this post in threaded view
|

Re: [ITK-users] [vtkusers] Convert vtkImageData to an itk::Image

Dženan Zukić
Hi Majid,

maybe you need to invoke reslice->Update(); before importing its output into ITK?

Regards,
Dženan

On Tue, Feb 13, 2018 at 11:31 AM, Majid M. Sadeghi via vtkusers <[hidden email]> wrote:
Dear All,

I read some DICOM data using vtkGDCMImageReader, then I change the sapacing and reslice them. Next I want to change that vtk image to itk image to be able to apply noise removal. But as soon as the code reaches the "filter_toitkimage->Update();" line the program just exits without saying anything (actually it says:The program '[14040] QtGuiApplication2.exe' has exited with code 3 (0x3).).

Here is the code:

vtkSmartPointer<vtkGDCMImageReader> reader = vtkSmartPointer<vtkGDCMImageReader>::New();
    reader->SetFileNames(vtkfiles);
    reader->Update();
   
    vtkSmartPointer<vtkImageChangeInformation> changer = vtkSmartPointer<vtkImageChangeInformation>::New();
    changer->SetOutputSpacing(pixlespacing, pixlespacing, ippzspacing);//@majidnow
    changer->SetInputConnection(reader->GetOutputPort());

    vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
    reslice->SetInputConnection(changer->GetOutputPort());
   
    //to change VTK image to ITK image
    const unsigned int Dimension = 3;

    using PixelType = double;
    using ImageType = itk::Image< PixelType, Dimension >;

    using FilterType = itk::VTKImageToImageFilter< ImageType >;
    FilterType::Pointer filter_toitkimage = FilterType::New();
    filter_toitkimage->SetInput(reslice->GetOutput());

    try
    {
        filter_toitkimage->Update();
    }
    catch (itk::ExceptionObject & error)
    {
        std::cerr << "Error: " << error << std::endl;
        //return EXIT_FAILURE;
    }
 

Any idea why this happens?


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers



The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
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.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
https://itk.org/mailman/listinfo/insight-users
Reply | Threaded
Open this post in threaded view
|

Re: [ITK-users] [vtkusers] Convert vtkImageData to an itk::Image

ITK - Users mailing list
Thanks, that did the job, sometimes silly mistakes create a headache.
 


On Tuesday, February 13, 2018 10:17 PM, Dženan Zukić <[hidden email]> wrote:


Hi Majid,

maybe you need to invoke reslice->Update(); before importing its output into ITK?

Regards,
Dženan

On Tue, Feb 13, 2018 at 11:31 AM, Majid M. Sadeghi via vtkusers <[hidden email]> wrote:
Dear All,

I read some DICOM data using vtkGDCMImageReader, then I change the sapacing and reslice them. Next I want to change that vtk image to itk image to be able to apply noise removal. But as soon as the code reaches the "filter_toitkimage->Update();" line the program just exits without saying anything (actually it says:The program '[14040] QtGuiApplication2.exe' has exited with code 3 (0x3).).

Here is the code:

vtkSmartPointer< vtkGDCMImageReader> reader = vtkSmartPointer< vtkGDCMImageReader>::New();
    reader->SetFileNames(vtkfiles) ;
    reader->Update();
   
    vtkSmartPointer< vtkImageChangeInformation> changer = vtkSmartPointer< vtkImageChangeInformation>:: New();
    changer->SetOutputSpacing( pixlespacing, pixlespacing, ippzspacing);//@majidnow
    changer->SetInputConnection( reader->GetOutputPort());

    vtkSmartPointer< vtkImageReslice> reslice = vtkSmartPointer< vtkImageReslice>::New();
    reslice->SetInputConnection( changer->GetOutputPort());
   
    //to change VTK image to ITK image
    const unsigned int Dimension = 3;

    using PixelType = double;
    using ImageType = itk::Image< PixelType, Dimension >;

    using FilterType = itk::VTKImageToImageFilter< ImageType >;
    FilterType::Pointer filter_toitkimage = FilterType::New();
    filter_toitkimage->SetInput( reslice->GetOutput());

    try
    {
        filter_toitkimage->Update();
    }
    catch (itk::ExceptionObject & error)
    {
        std::cerr << "Error: " << error << std::endl;
        //return EXIT_FAILURE;
    }
 

Any idea why this happens?


______________________________ _________________
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

Search the list archives at: http://markmail.org/search/?q= vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/ listinfo/vtkusers





The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
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.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
https://itk.org/mailman/listinfo/insight-users