[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 10:21:11 EDT 2003


Hi,

I followed Amys suggestion of using vtkXMLImageDataWriter
seemed sensible to write the tiff stack as a vtk image file, right,

but now I get this error about vtkImageLuminance : input must have 3  
components, but has 4
my tiff files are grey scale 8 bit tiff, nothing weird i think. I don't  
know what this error means.


[daniel:~/Desktop/volumerender] dan% python2.3 tiffstack2vtk.py  
tiffseries/tiffseriestest
ERROR: In /Applications/vtksources/VTK/Imaging/vtkImageLuminance.cxx,  
line 85
vtkImageLuminance (0x1413040): Execute: input must have 3 components,  
but has 4

here is my current script

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%03i.tif")    #change to fit filename
reader1.SetDataExtent(0,511,0,511,0,55) #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 = vtkImageDataGeometryFilter ()   # will it work?
#converter.SetInput(reader.GetOutput())


# Data writer

writer = vtk.vtkXMLImageDataWriter()         #or should it be something  
else
writer.SetFileName('vtkfileout.vtk')      #change vtkfileout to  
whatever filename you want
writer.SetInput(reader.GetOutput())

# write the file to disk...
writer.Write()

[daniel:~/Desktop/volumerender] dan%
>
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