[vtkusers] TIFF data set incorrectly displayed -what am I doing wrong!?
Dr. Dan White
dan at chalkie.org.uk
Fri Oct 4 09:42:43 EDT 2002
Dear all,
I'm trying to volume render a set of 20 z slices in tiff format in a
tk window using a python script modified from one found at atamai.org
(tkvolumelod.py) My data seems not to be read properly. The tiff
files are from a confocal microscope, and are a series of z slices
through a living cell. Data is from PC, but I am doing this on linux,
so I have to SetDataByteOrderToLittleEndian() right (see script
below)? The data should look like a hollow half sphere, but appears
as arrays of little rectangles, no matter how I adjust the opacity
and colour transfer functions in the script.
My python script is below (modified from atamai.org so it reads tiff
files as a dataset)
I am using vtkTIFFReader, and believe I am specifying the fileseries
as a 102x119x20 data set with 1x1x3 spacing.
my command is like
python volrendscript.py fileprefix
my tiff files are named for instance
fileprefix01.tif
fileprefix02.tif
etc . to
fileprefix20.tif
In gimp if I look at one of the tiff images in the middle of the
stack and do a histogram I can see that there a re pixels of all
values from 0 to 255. It seems like data is loaded and something is
displayed (no segmentation faults, or other errors at the command
prompt, and I can rotate it around and zoom just fine), but it looks
nothing like the images the rendered dataset is made from. The bottom
of the stack seems to be displayed with high values (in my case
green) and the higher slices are orange then red at the top. Seems
like the problem might lie here?
Hope someone can spot my problem...I'm stumped!
Cheers
Dan
#!/usr/local/bin/python
from Tkinter import *
# check for correct usage
import sys
if sys.argv[1:]:
filename = sys.argv[1]
else:
filename = "phantom.mnc"
# load the VTK stuff
import paths
from RenderPane import *
from VolumeFactory import *
from ConeCursorFactory import *
# put together the VTK rendering pipeline
# read the files and add them to the othoplanes
reader = vtkTIFFReader()
reader.SetFilePrefix(filename)
reader.SetFilePattern("%s%02i.tif")
reader.SetDataExtent(0,101,0,118,1,20)
reader.SetDataSpacing(1,1,3)
reader.SetDataByteOrderToLittleEndian()
(minval,maxval) = (0,255)
input = reader.GetOutput()
cast0 = vtkImageShiftScale()
cast0.SetInput(reader.GetOutput())
cast0.SetShift(-minval)
cast0.SetScale(255.0/(maxval-minval))
cast0.SetOutputScalarTypeToUnsignedChar()
cursor = ConeCursorFactory()
opacityTransferFunction0 = vtkPiecewiseFunction()
opacityTransferFunction0.AddPoint( 0 , 0.0 )
opacityTransferFunction0.AddPoint( 50 , 0.1 )
opacityTransferFunction0.AddPoint( 100, 0.1 )
opacityTransferFunction0.AddPoint( 150, 0.2 )
opacityTransferFunction0.AddPoint( 255, 0.2 )
colorTransferFunction0 = vtkColorTransferFunction()
# colorTransferFunction0.AddHSVPoint( 0, 0.02, 0.8, 0.0 )
# colorTransferFunction0.AddHSVPoint( 100, 0.02, 0.4, 0.6 )
# colorTransferFunction0.AddHSVPoint( 255, 0.03, 0.2, 1.0 )
colorTransferFunction0.AddHSVPoint( 0 , 0.00, 1.0, 1.0 )
colorTransferFunction0.AddHSVPoint( 100, 90.0, 1.0, 1.0 )
colorTransferFunction0.AddHSVPoint( 255, 270.0, 1.0, 1.0 )
colorTransferFunction0.SetColorSpaceToHSV()
# set up the volume
volume = VolumeFactory()
volume.SetInput(cast0.GetOutput())
volume.SetColorTransferFunction(colorTransferFunction0)
volume.SetOpacityTransferFunction(opacityTransferFunction0)
volume.GetVolumeProperty().ShadeOff()
volume.SetPickThreshold(0.99)
root = Tk()
# create the rendering pane, add the actors
pane = RenderPane(root,width=500,height=500)
pane.ConnectActorFactory(volume)
pane.ConnectCursor(cursor)
pane.pack(expand='true',fill='both')
volume.Render()
root.mainloop()
# end of python script
dan at chalkie.org.uk
http://www.chalkie.org.uk
Daniel James White PhD.
Cell Biology
Department of Biological and Environmental Science
University of Jyväskylä
FIN-40351
Jyväskylä
Finland
+358 (0)14 260 4183 (office)
More information about the vtkusers
mailing list