[vtkusers] ImagePlaneWidget mapping ImageData with 3 scalars to rgb
Lars Matthäus
lars.matthaeus at web.de
Thu Oct 1 03:21:59 EDT 2015
Great, that worked! Never had the idea that it would be possible to set
just no color table at all...
Thanks very much,
Lars
Am 30.09.2015 um 21:00 schrieb DL I:
> Hi Lars,
>
> I think the problem is the vtkLookupTable is meant to take a single
> component (scalar value) and map it to RGB.
> So even though the image has 3 unsigned char components, only the first
> component gets mapped through. What you want
> to do in this case is just pass the image directly through without using
> a lookup table. However, with 3D image data, you might
> not be able to do window levelling: not sure, just a hunch at this
> point. Also, you dont need to set a vtkLookupTable to
> the vtkImageSlice's vtkImageProperty since the image is already 3
> unsigned char.
> The following worked for me:
>
> #include <vtkImageMapToColors.h>
> #include <vtkImagePlaneWidget.h>
> #include <vtkImageData.h>
> #include <vtkSmartPointer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkInteractorStyleImage.h>
> #include <vtkRenderer.h>
> #include <vtkImageMapper.h>
> #include <vtkImageSliceMapper.h>
> #include <vtkImageProperty.h>
> #include <vtkImageSlice.h>
> #include <vtkLookupTable.h>
> #include <vtkJPEGReader.h>
>
> int main(void) {
>
> // Setup renderers
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
>
> // Setup render window
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->SetSize(800, 800);
> renderWindow->AddRenderer(renderer);
>
> // Setup render window interactor
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> // create input
> vtkSmartPointer<vtkJPEGReader> reader =
> vtkSmartPointer<vtkJPEGReader>::New();
>
> reader->SetFileName("/home/dean/files/repository/VTKData/Data/beach.jpg");
> vtkImageData* id = reader->GetOutput();
> reader->Update();
> int* dim = id->GetDimensions();
>
> // image plane widget
> vtkSmartPointer<vtkImagePlaneWidget> ipw =
> vtkSmartPointer<vtkImagePlaneWidget>::New();
> ipw->SetInteractor(renderWindowInteractor);
> ipw->SetInput(reader->GetOutput());
> ipw->SetPlaneOrientation(2);
> ipw->GetColorMap()->SetLookupTable(NULL);
> ipw->GetColorMap()->SetOutputFormatToRGB();
> ipw->On();
>
> // slice mapper
> vtkSmartPointer<vtkImageSliceMapper> imageMapper =
> vtkSmartPointer<vtkImageSliceMapper>::New();
> imageMapper->SetInput(reader->GetOutput());
>
> vtkSmartPointer<vtkImageSlice> image =
> vtkSmartPointer<vtkImageSlice>::New();
> image->SetMapper(imageMapper);
> image->SetPosition(1.5 * dim[0], 0, 0); // shift in x direction
> renderer->AddViewProp(image);
>
> // proper initial display
> renderer->ResetCamera();
>
> // Render and start interaction
> renderWindowInteractor->Initialize();
>
> renderWindowInteractor->Start();
>
> return EXIT_SUCCESS;
> }
>
> - Dean
>
> 1,5 Top
>
>
>
>
> On Wed, Sep 30, 2015 at 3:44 AM, Lars Matthäus <lars.matthaeus at web.de
> <mailto:lars.matthaeus at web.de>> wrote:
>
> Dear Dean,
>
> Thanks for your help! Unfortunately, it doesn't solve the problem. The
> image in the vtkImagePlaneWidget is still not like the original rgb. I
> attach again some screenshots for comparison (vtkImagePlaneWidget on the
> left, vtkImageSliceMapper on the right). Is there anything else I
> could try?
>
> Best,
> Lars
>
> Am 29.09.2015 um 15:22 schrieb DL I:
> > Lars,
> > try changing your value and saturation ranges to something else, like (1,1)
> > regards,
> > Dean
> >
> > On Mon, Sep 28, 2015 at 10:29 AM, Lars Matthäus <lars.matthaeus at web.de <mailto:lars.matthaeus at web.de>
> > <mailto:lars.matthaeus at web.de <mailto:lars.matthaeus at web.de>>> wrote:
> >
> > I have a DataSet with 3 scalar components, e.g. from loading a stack of
> > rgb images with the vtkJPEGReader. I want to slice through it using a
> > vtkImagePlaneWidget. Unfortunately, I cannot get the widget to display
> > the rgb image; I only get a grey image.
> >
> > I played with the vtkLookupTable::SetVectorModeToRGBColors successfully
> > to display the image as rgb using a vtkImageSliceMapper, but when I use
> > the same lookup table for the vtkImagePlaneWidget, I get a grey
> > image again.
> >
> > I attach some java sample code comparing the vtkImagePlaneWidget and the
> > vtkImageSliceMapper as well as the output of the program.
> >
> > Any help appreciated!
> > Lars
> >
> > _______________________________________________
> > Powered by www.kitware.com <http://www.kitware.com>
> <http://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:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
> >
>
>
More information about the vtkusers
mailing list