[vtkusers] Can you Fix my very simple problem? convert tiff series/stack to .vtk file with python script?

Amy Henderson amy.henderson at kitware.com
Fri Oct 10 09:56:49 EDT 2003


Hi Dan,

If you want to convert your stack of tiffs into a .vtk file, it should be a 
vtkImageData (or vtkStructuredPoints), not a vtkStructuredGrid.  Read your 
stack of tiffs into VTK as you are already doing.  Then set the output of 
the tiff reader to be the input of a vtkStructuredPointsWriter or a 
vtkXMLImageDataWriter.

However it is not necessary to convert your tiffs to a .vtk file to read 
them into VTK, ParaView, or VolView; they can read stacks of tiffs 
directly.  (I can't speak for MayaVi.)

- Amy

At 04:43 PM 10/10/2003 +0300, Dr. Daniel James White PhD wrote:
>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
>_______________________________________________
>This is the private VTK discussion list. Please keep messages on-topic. 
>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers






More information about the vtkusers mailing list