[vtkusers] [Insight-users] How to show dicoms with vtk (ImageToVTKImageFilter)

Jothy jothybasu at gmail.com
Mon Jul 18 04:53:50 EDT 2011


As far as I know, you can't simply set the output of file reader to
vtkActor. It should be mapped through a vtkLookupTable and mapper.

it should be something like below

// Create a greyscale lookup table

        vtkSmartPointer<vtkLookupTable> table =

          vtkSmartPointer<vtkLookupTable>::New();

        table->SetRange(-600,900); // image intensity range

        table->SetValueRange(0.0, 1.0); // from black to white

        table->SetSaturationRange(0.0, 0.0); // no color saturation

        table->SetRampToLinear();

        table->Build();

         // Map the image through the lookup table

        vtkSmartPointer<vtkImageMapToColors> color =

          vtkSmartPointer<vtkImageMapToColors>::New();

        color->SetLookupTable(table);

        color->SetInputConnection(reader->GetOutput());

         // Set the image

          this->axialSlice->SetInput(color->GetOutput());


Since this this mainly vtk related , you should post it to vtk list too. (I
have added a cc)

HTH

Jothy

On Mon, Jul 18, 2011 at 3:25 AM, soheilghafurian
<soheilghafurian at yahoo.com>wrote:

> My problem is I load a dicom file and I try to show it through vtk by
> ImageToVTKImageFilter. But the result is kind of distorted. I think the
> problem is because the pixeltype is not good, but when I use another type,
> I
> get this message when the program is running:
>
> ERROR: In ..\..\Rendering\vtkImageActor.cxx, line 267
> vtkOpenGLImageActor (058C5340): This filter requires unsigned char scalars
> as input
>
> Could anyone help me on how I should solve this problem? here is the code:
>
> int main()
> {
>        char *fName = fl_file_chooser("Pick the fixed dicom Image", "*.dcm",
> ".");
>      if(fName == NULL) return 0;
>
>          typedef itk::Image< unsigned char, 2> ImageType;
>  typedef itk::ImageFileReader<ImageType>             ReaderType;
>  typedef itk::ImageToVTKImageFilter<ImageType>       ConnectorType;
>
>  ReaderType::Pointer reader = ReaderType::New();
>  ConnectorType::Pointer connector = ConnectorType::New();
>
>  reader->SetFileName(fName);
>  reader->Update();
>  connector->SetInput(reader->GetOutput());
>
>
>
>  vtkSmartPointer<vtkImageActor> actor =
>    vtkSmartPointer<vtkImageActor>::New();
> //  actor->SetInput(connector->GetOutput());
>  actor->SetInput(connector->GetOutput());
>
>  vtkSmartPointer<vtkRenderer> renderer =
>    vtkSmartPointer<vtkRenderer>::New();
>  renderer->AddActor(actor);
>  renderer->ResetCamera();
>
>  vtkSmartPointer<vtkRenderWindow> renderWindow =
>    vtkSmartPointer<vtkRenderWindow>::New();
>  renderWindow->AddRenderer(renderer);
>
>  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>    vtkSmartPointer<vtkRenderWindowInteractor>::New();
>  vtkSmartPointer<vtkInteractorStyleImage> style =
>    vtkSmartPointer<vtkInteractorStyleImage>::New();
>
>  renderWindowInteractor->SetInteractorStyle(style);
>
>  renderWindowInteractor->SetRenderWindow(renderWindow);
>  renderWindowInteractor->Initialize();
>
>  renderWindowInteractor->Start();
>
>  return EXIT_SUCCESS;
> }
>
>
>
> --
> View this message in context:
> http://itk-insight-users.2283740.n2.nabble.com/How-to-show-dicoms-with-vtk-ImageToVTKImageFilter-tp6593222p6593222.html
> Sent from the ITK Insight Users mailing list archive at Nabble.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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110718/04ad27f1/attachment.htm>


More information about the vtkusers mailing list