This example may help you: <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/Transparency">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/Transparency</a><br><br><div class="gmail_quote">On Mon, Feb 21, 2011 at 11:47 PM, kigras <span dir="ltr"><<a href="mailto:kigras@gmail.com">kigras@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hi,<br>
I would like to visualize two images at the same time in one renderer window<br>
(CT and binary images in vtkImageViewer2). In my opinnion using vtkBlend is<br>
a good direction to follow. However, I encounter some problems. At present,<br>
In my software I can simple visualize CT slice with all functionality<br>
provided by vtkImageViewer2, i need to preserve that functionality ie.<br>
window level adjustment. Now I have binary image (with the same size), my<br>
goal is to make transparent all black pixels and color to half transparent<br>
yellow all object pixels. However, when I use following code the results are<br>
not as I have expected.<br>
<br>
This is my code:<br>
<br>
//read raw file<br>
<br>
vtkImageReader *ImageReader = vtkImageReader::New();<br>
ImageReader->SetFileName("p1tree.raw");<br>
ImageReader->SetDataScalarTypeToUnsignedChar();<br>
ImageReader->SetDataByteOrder(0);<br>
ImageReader->SetFileDimensionality(3);<br>
ImageReader->SetDataOrigin (0.0, 0.0, 0.0);<br>
ImageReader->SetDataSpacing(1.0 ,1.0, 1.0);<br>
ImageReader->SetDataExtent( 0,431, 0, 270, 0, 444);<br>
ImageReader->SetNumberOfScalarComponents(1);<br>
<br>
//input=ImageReader->GetOutput();<br>
ImageReader->Update();<br>
vtkImageReader *ImageReader1 = vtkImageReader::New();<br>
ImageReader1->SetFileName("p1.raw");<br>
ImageReader1->SetDataScalarTypeToShort();<br>
ImageReader1->SetDataByteOrder(1);<br>
ImageReader1->SetFileDimensionality(3);<br>
ImageReader1->SetDataOrigin (0.0, 0.0, 0.0);<br>
ImageReader1->SetDataSpacing(1.0 ,1.0, 1.0);<br>
ImageReader1->SetDataExtent( 0,431, 0, 270, 0, 444);<br>
ImageReader1->SetNumberOfScalarComponents(1);<br>
ImageReader1->Update();<br>
<br>
//color<br>
<br>
vtkSmartPointer<vtkLookupTable> FirstColorMap =<br>
vtkSmartPointer<vtkLookupTable>::New();<br>
<br>
//binary<br>
FirstColorMap->SetTableValue(0, 0.2000, 0.6300, 0.7900, 1);<br>
FirstColorMap->Build();<br>
<br>
//CT<br>
vtkSmartPointer<vtkLookupTable> ColorMap =<br>
vtkSmartPointer<vtkLookupTable>::New(); // hot color map]<br>
<br>
ColorMap->SetTableValue(0, 0.8900, 0.8100, 0.3400, 1);<br>
ColorMap->Build();<br>
<br>
vtkImageCast *cast = vtkImageCast::New();<br>
<br>
cast->SetInput(ImageReader->GetOutputDataObject(0));<br>
cast->SetOutputScalarTypeToShort();<br>
cast->ClampOverflowOn();<br>
cast->Print(std::cout);<br>
<br>
<br>
vtkSmartPointer<vtkImageMapToColors> ColorMapper =<br>
vtkSmartPointer<vtkImageMapToColors>::New();<br>
ColorMapper->SetInput( cast->GetOutput() );<br>
ColorMapper->SetLookupTable( FirstColorMap );<br>
<br>
vtkSmartPointer<vtkImageMapToColors> ColorMapper1 =<br>
vtkSmartPointer<vtkImageMapToColors>::New();<br>
ColorMapper1->SetInput( ImageReader1->GetOutput() );<br>
ColorMapper1->SetLookupTable( ColorMap );<br>
<br>
<br>
// Combine the images (blend takes multiple connections on the 0th input<br>
port)<br>
vtkSmartPointer<vtkImageBlend> blend =<br>
vtkSmartPointer<vtkImageBlend>::New();<br>
<br>
//blend->AddInputConnection(0,cast->GetOutputPort());<br>
//blend->AddInputConnection(0,ImageReader1->GetOutputPort());<br>
<br>
<br>
blend->AddInputConnection(0,ColorMapper->GetOutputPort());<br>
blend->AddInputConnection(0,ColorMapper1->GetOutputPort());<br>
<br>
blend->SetOpacity(0,1.0);<br>
blend->SetOpacity(1,.5);<br>
<br>
// Display the result<br>
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
<br>
vtkSmartPointer<vtkImageViewer2> imageViewer =<br>
vtkSmartPointer<vtkImageViewer2>::New();<br>
imageViewer->SetColorLevel(0);<br>
imageViewer->SetColorWindow(255);<br>
imageViewer->SetSliceOrientation(2);<br>
imageViewer->SetSlice(259);<br>
<br>
imageViewer->SetInputConnection(blend->GetOutputPort());<br>
imageViewer->SetupInteractor(renderWindowInteractor);<br>
imageViewer->GetRenderer()->ResetCamera();<br>
imageViewer->SetSize( 800, 800 );<br>
imageViewer->GetRenderer()->SetBackground(.1,.2,.3); //dark blue<br>
<br>
vtkRenderer *ren = vtkRenderer::New();<br>
vtkImageActor * mriActor = vtkImageActor::New();<br>
mriActor->SetInput(blend->GetOutput());<br>
ren->AddViewProp( mriActor );<br>
<br>
renderWindowInteractor->Initialize();<br>
renderWindowInteractor->Start();<br>
<br>
<br>
<br>
I attach a few pics what I want to result:<br>
<a href="http://vtk.1045678.n5.nabble.com/file/n3394758/bin.png" target="_blank">http://vtk.1045678.n5.nabble.com/file/n3394758/bin.png</a> // binary picture<br>
<a href="http://vtk.1045678.n5.nabble.com/file/n3394758/CT.png" target="_blank">http://vtk.1045678.n5.nabble.com/file/n3394758/CT.png</a> // CT picture<br>
<a href="http://vtk.1045678.n5.nabble.com/file/n3394758/CTandBIN.png" target="_blank">http://vtk.1045678.n5.nabble.com/file/n3394758/CTandBIN.png</a> // combined<br>
pictures this is my goal<br>
<br>
<br>
<br>
Thanks a lot for help.<br>
<br>
Jakub Igras<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/Blending-two-different-slices-of-raw-file-and-color-one-of-them-tp3394758p3394758.html" target="_blank">http://vtk.1045678.n5.nabble.com/Blending-two-different-slices-of-raw-file-and-color-one-of-them-tp3394758p3394758.html</a><br>
Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Jesús Spínola<br>