Hello vtk community,
first of all: Thank you for the great VTK Framework, which is an amazing Tool!
As a beginner i am just starting a first project using vtk and python to show a 3D representation/rendering from a Tiffstack (RGB). My goal is to show the rendering in original Tiff Color and a transparent Background (as shown here with 3dslicer: https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294). So far i get it, at least, halfway working.
Here you see my code (using some example code from the web with few modifications):
####################################
import vtk
filename = “Tiffilewith250imagesRGB.tif”
colors = vtk.vtkNamedColors()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
reader = vtk.vtkTIFFReader()
reader.SetFileName(filename)
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(20, 0)
opacityTransferFunction.AddPoint(255, 1)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOn()
volumeProperty.SetInterpolationTypeToLinear()
volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()
volumeMapper.SetInputConnection(reader.GetOutputPort())
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
ren1.AddVolume(volume)
ren1.SetBackground(colors.GetColor3d(“Wheat”))
ren1.GetActiveCamera().Azimuth(45)
ren1.GetActiveCamera().Elevation(30)
ren1.ResetCameraClippingRange()
ren1.ResetCamera()
renWin.SetSize(600, 600)
renWin.Render()
iren.Start()
##################
However this shows some colored 3d rendering inside a blackbox. Like i said before, my goal is to show this rendering without the blackbox, so just the colored Image where the original white Image Background is transparent.
Is there any way to do so? Any help or links are very welcome.
Best regards
Bastian