[vtkusers] Change the color of a single specific value in the image. VTK

Héber de Padua Sousa hebersousa at gmail.com
Tue Oct 19 09:30:12 EDT 2010


I'm trying to read a DICOM image and change the color of a single specific
value.
I am using vtkLookupTable.
But is having a strange behavior.
The image not is showed, but a lot of noise.
What can be?

code:
#include <cstdio>
#include <iostream>
#include "vtkImageData.h"
#include "vtkImageViewer2.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkDICOMImageReader.h"
#include "vtkImageMapToColors.h"
#include "vtkLookupTable.h"

using namespace std;


int main()
{

vtkDICOMImageReader *reader = vtkDICOMImageReader :: New();
 reader-> SetDirectoryName("C:\\volumes\\exemplo2");

 reader->Update();


 vtkLookupTable* table = vtkLookupTable::New();

   double* range = reader->GetOutput()->GetScalarRange();
   printf("\nrange %lf %lf
[1]-[0]=%lf\n",range[0],range[1],range[1]-range[0]);

   table->SetNumberOfColors( range[1]-range[0] );
   table->SetTableRange(range[0],range[1]);
   table->SetSaturationRange(0,0);
   table->SetHueRange(0,1);
   table->SetValueRange(0,1);
   table->SetAlphaRange(1,1);

   // set new color
   table->SetTableValue(0,0.0,1.0,0.0,0.0);

   table->Build();


  //convert to color:
  vtkImageMapToColors* colormap = vtkImageMapToColors::New();
  colormap->SetInput(reader->GetOutput());
  colormap->SetLookupTable(table);
  colormap->SetOutputFormatToRGB();

 vtkRenderWindowInteractor* ite = vtkRenderWindowInteractor::New();

 vtkImageViewer2* viewer = vtkImageViewer2::New();
 viewer->SetInputConnection( colormap->GetOutputPort() );
  viewer->SetupInteractor( ite );

  ite->Initialize();
  ite->Start();

return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101019/b3765669/attachment.htm>


More information about the vtkusers mailing list