[vtkusers] Can you Fix my very simple problem? convert tiff series/stack to .vtk file with python script?
    Dr. Daniel James White PhD 
    dan at chalkie.org.uk
       
    Fri Oct 10 09:43:45 EDT 2003
    
    
  
Hi all,
A very simple problem I'm sure only takes a moment to fix......
I'm trying to write a python script to convert series/stacks of tiff  
images from our confocal microscope
into some .vtk file that can be then read by VTK / MayaVi / VolView /  
ParaView etc
The Data sets are slices through living cells etc, and need to be  
reconstructed into a 3D data set for visualisation
Here is what I have so far..... I think it reads the stack/series of  
tiff files into a 3D image OK,
but it fails at the point of conversion of the image data into a
structured grid (is this the right thing to do?) which can then be  
written as a vtkStructuredGrid
with vtkStructuredGridWriter.
what am I doing wrong...... I'm sure its very simple...
cheers
Dan
#!/usr/bin/env python
# tiffstack2vtk.py
# tiff series to .vtk conversion script
# Dan White 2003
#----------------------------------------------------------------------- 
----
# Code begins
import types,sys
if sys.argv[1:]:
   filename = sys.argv[1]
else:
   filename = "whatnofilename.tif" # default filename
from vtkpython import *
# Build the vtk pipeline
# Data reader
reader1 = vtkTIFFReader ()
reader1.SetFilePrefix(filename)
reader1.SetFilePattern("%s%02i.tif")    #change to fit filename
reader1.SetDataExtent(0,182,0,212,0,24) #change to fit image size
reader1.SetDataSpacing(1,1,2.45)        #change to fit z spacing vs x,y
reader1.SetDataByteOrderToBigEndian     #only needed if more than one  
byte per pixel
reader = vtkImageLuminance ()
reader.SetInput (reader1.GetOutput())
# Convert image to structured grid, I think I need to do this right?
converter = vtkDataSetToStructuredGridFilter ()   # OK this like  
doesn't work as it is an abstract class
converter.SetInput(reader.GetOutput())                 # so how should  
I do it then?
# Data writer
writer = vtk.vtkStructuredGridWriter()    #or should it be something  
else
writer.SetFileName('vtkfileout.vtk')      #change vtkfileout to  
whatever filename you want
writer.SetInput(converter.GetOutput())
# write the file to disk...
writer.Write()
Dr. Daniel James White BSc. (Hons.) PhD
Cell Biology
Department of biological and environmental science
PO Box  35
University of Jyväskylä
Jyväskylä FIN 40014
Finland
+358 (0)14 260 4183 (work)
+358 (0)414740463 (mob)
http://www.chalkie.org.uk
dan at chalkie.org.uk
white at cc.jyu.fi
    
    
More information about the vtkusers
mailing list