[vtkusers] Blending two different slices of raw file and color one of them

kigras kigras at gmail.com
Mon Feb 21 17:47:45 EST 2011


 Hi, 
I would like to visualize two images at the same time in one renderer window
(CT and binary images in vtkImageViewer2). In my opinnion using vtkBlend is
a good direction to follow. However, I  encounter some problems. At present,
In my software I can simple visualize CT slice with all functionality
provided by vtkImageViewer2, i need to preserve that functionality ie.
window level adjustment. Now I have binary image (with the same size), my
goal is to make transparent all black pixels and color to half transparent
yellow all object pixels. However, when I use following code the results are
not as I have expected.

This is my code:

     //read raw file

    vtkImageReader *ImageReader =  vtkImageReader::New();
    ImageReader->SetFileName("p1tree.raw");
    ImageReader->SetDataScalarTypeToUnsignedChar();
    ImageReader->SetDataByteOrder(0);
    ImageReader->SetFileDimensionality(3);
    ImageReader->SetDataOrigin (0.0, 0.0, 0.0);
    ImageReader->SetDataSpacing(1.0 ,1.0, 1.0);
    ImageReader->SetDataExtent( 0,431, 0, 270, 0, 444);
    ImageReader->SetNumberOfScalarComponents(1);

    //input=ImageReader->GetOutput();
    ImageReader->Update();
    vtkImageReader *ImageReader1 =  vtkImageReader::New();
    ImageReader1->SetFileName("p1.raw");
    ImageReader1->SetDataScalarTypeToShort();
    ImageReader1->SetDataByteOrder(1);
    ImageReader1->SetFileDimensionality(3);
    ImageReader1->SetDataOrigin (0.0, 0.0, 0.0);
    ImageReader1->SetDataSpacing(1.0 ,1.0, 1.0);
    ImageReader1->SetDataExtent( 0,431, 0, 270, 0, 444);
    ImageReader1->SetNumberOfScalarComponents(1);
    ImageReader1->Update();

    //color

    vtkSmartPointer<vtkLookupTable> FirstColorMap =
      vtkSmartPointer<vtkLookupTable>::New();

//binary
        FirstColorMap->SetTableValue(0, 0.2000, 0.6300, 0.7900, 1);
        FirstColorMap->Build(); 

//CT
   vtkSmartPointer<vtkLookupTable> ColorMap =
     vtkSmartPointer<vtkLookupTable>::New(); // hot color map]
   
       ColorMap->SetTableValue(0, 0.8900, 0.8100, 0.3400, 1);
       ColorMap->Build();

      vtkImageCast *cast = vtkImageCast::New();

      cast->SetInput(ImageReader->GetOutputDataObject(0));
      cast->SetOutputScalarTypeToShort();
      cast->ClampOverflowOn();
      cast->Print(std::cout);


      vtkSmartPointer<vtkImageMapToColors> ColorMapper =
          vtkSmartPointer<vtkImageMapToColors>::New();
      ColorMapper->SetInput( cast->GetOutput() );
      ColorMapper->SetLookupTable( FirstColorMap );

      vtkSmartPointer<vtkImageMapToColors> ColorMapper1 =
          vtkSmartPointer<vtkImageMapToColors>::New();
      ColorMapper1->SetInput( ImageReader1->GetOutput() );
      ColorMapper1->SetLookupTable( ColorMap );


    // Combine the images (blend takes multiple connections on the 0th input
port)
    vtkSmartPointer<vtkImageBlend> blend =
      vtkSmartPointer<vtkImageBlend>::New();

    //blend->AddInputConnection(0,cast->GetOutputPort());
    //blend->AddInputConnection(0,ImageReader1->GetOutputPort());

 
    blend->AddInputConnection(0,ColorMapper->GetOutputPort());
    blend->AddInputConnection(0,ColorMapper1->GetOutputPort());

    blend->SetOpacity(0,1.0);
    blend->SetOpacity(1,.5);

    // Display the result
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();

    vtkSmartPointer<vtkImageViewer2> imageViewer =
      vtkSmartPointer<vtkImageViewer2>::New();
    imageViewer->SetColorLevel(0);
    imageViewer->SetColorWindow(255);
    imageViewer->SetSliceOrientation(2);
    imageViewer->SetSlice(259);

    imageViewer->SetInputConnection(blend->GetOutputPort());
    imageViewer->SetupInteractor(renderWindowInteractor);
    imageViewer->GetRenderer()->ResetCamera();
    imageViewer->SetSize( 800, 800 );
    imageViewer->GetRenderer()->SetBackground(.1,.2,.3); //dark blue

    vtkRenderer *ren = vtkRenderer::New();
    vtkImageActor * mriActor = vtkImageActor::New();
    mriActor->SetInput(blend->GetOutput());
    ren->AddViewProp( mriActor );

    renderWindowInteractor->Initialize();
    renderWindowInteractor->Start();



I attach a few pics what I want to result: 
http://vtk.1045678.n5.nabble.com/file/n3394758/bin.png  // binary picture
http://vtk.1045678.n5.nabble.com/file/n3394758/CT.png  // CT picture
http://vtk.1045678.n5.nabble.com/file/n3394758/CTandBIN.png  // combined
pictures this is my goal



Thanks a lot for help.

Jakub Igras
-- 
View this message in context: http://vtk.1045678.n5.nabble.com/Blending-two-different-slices-of-raw-file-and-color-one-of-them-tp3394758p3394758.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list