Colored Volume from Tiffstack/MultiImageTiff

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: 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()

iren = vtk.vtkRenderWindowInteractor()

reader = vtk.vtkTIFFReader()

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()

volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()

volume = vtk.vtkVolume()

renWin.SetSize(600, 600)


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

The step that you are missing is the interactive editing of the scalar opacity transfer function to make the dark regions transparent. I would recommend to use the script provided on the Slicer forum to visualize the volume in 3D Slicer and use the Volume rendering module there to specify a transfer function with a ramp shape, assigning 0 opacity to low intensity values and 0.1 to 1.0 to higher intensity values. Once you determined a good transfer function, you can recreate it easily from your Python script.

1 Like

Thanks a lot for youranswer!
I will try this out as soon as possible.

Best Regards

1 Like

Hi Andras,

i tried to “configure” the Transfer-Function via Slicer like you suggested. But still the result looks pretty much the same as before (see the attached Image of the Slicer and the Python outcome). The only thing in my code i changed was the following:

Create transfer mapping scalar value to opacity.
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(0, 0)
opacityTransferFunction.AddPoint(20, 0)
opacityTransferFunction.AddPoint(40, 0.15)
opacityTransferFunction.AddPoint(98.26, 0.71)
opacityTransferFunction.AddPoint(253, 0)

I think i still did not have enaugh knowledge of the color and transferfunctions to solve this problem alone. But i think one problem could be, that i did not get the true colors/original colors from the images (which i do when using slicer App to configure the Values of the transfer function) and therefore the values of the transferfunction do not match up in my code.

I go on reading the TextBook/UsersManuel of VTK, but any help or recommendations are highly appreciated :slight_smile:

Best regards

PS: I uploaded a tiff-file containing 4 images as an example of my input Data. As i am a new user, i uploaded it here:

Do I see correctly that in Slicer you managed to remove the black border?

If you expect to see more inside the volume then decrease the opacity values.

If you have extremely large or small image spacing that may impact rendering image quality, too. You can adjust it in Volumes module Volume Information section.

What do you expect to see in the image?

Hi Andras,

my goal is to get my tiffstack shown in 3d like shown above in the slicer3d app.
As Background Info: The Tiffstack is made from Layerwise Pyrometer measurements of a 3d printing process. Each Image in the Tiff-File represents the Pyrometer measurements of one printed Layer.
As we have some printed parts with over 1000 Layers, looking at all the Raw Pyrometer Data to find some “defects” or, to put it more general, some regions of interest, is pretty much work.
Therefore i like to see all the Data in one 3d model made from the multiimage tiff to get a direct inside view of the whole part. So i can directly see the regions of interest, and how they eventually “grow” over the Layers. This works pretty good in the slicer app, so i thought it would be great to write a python skript myself, where i can include some functions for analyzing the raw data too, after i found the interesting Layers within the 3d Model. I hope this gives a better understanding of what and why i am trying this.

However, in Slicer3d, after i entered the python script, i get the original image color in the 3d Model and i can configure the scalar opacity mapping to get rid of the black “box” sorrounding the interesting region.
After reading your post in the slicer forum aggain, i think what i am missing is maybe this: “convert it to add an alpha channel and enable direct RGBA volume rendering”.

For me it looks like vtk “sees” my tiffstack as kind of Grayscale images and not as the real colored images. (Correct me if i am wrong, as i mentioned, i am pretty new to vtk…)

Thanks a lot for your help!
Best Regards

Everything that you need is described in the script in the Slicer forum post:

You need to turn off “independent components” (so that scalar components of the image are interpreted as RGBA color) and you need to add an alpha channel if your image is not already RGBA (so that you can make dark regions fully transparent).

1 Like

Hi Andras,

i am sorry, but i am not able to solve this issue. My Tiffs are RGB, so, like u said, i have to add the alpha channel in my Python code.
From the Slicer Forum i know how to do this in the python shell of the slicer app, but i am not able to repruduce this in my own python script (mainly because i dont find the equivalent to these functions in python vtk: colorVolume.GetImageDataConnection()).
Tried to find a solution one day long and couldnt find one. Sorry to ask aggain, but maybe you can help.

Best Regards