[vtkusers] vtk+OS X: can't read *.tiff files

Karl Garsha garsha at itg.uiuc.edu
Fri Apr 1 13:43:54 EST 2005


An update: the crashing interpreter is due to some sort of conflict 
between the PyCrust interpreter or wxWindows and Python/VTK.  When I run 
a simple interpreter from the shell prompt, I can read *.tif files.  I'm 
still having render window problems though; vtkImageViewer just shows up 
for a split second with nothing in it and then dissappears.  I'm using 
the Carbon build. I have an older Fink VTK build that does the same 
thing in X11.  I'm just calling the Render() function of the 
ImageViewer, am I missing something?  An example of the code I'm using 
is below.  The only wierd thing I'm doing is using 8-bit color indexed 
tiff files; clearly I'm doing something wrong but I can't seem to figure 
out what it is that I'm forgetting.

#! python

class ImageRdDsply:
    def __init__(self, imgname):
        global ImgName
        global ImgData
        self.ImgName=imgname
        self.ReadImage_8bit()

    def ReadImage_8bit(self):
        import vtk
        TIFFReader=vtk.vtkTIFFReader()
        Reader=vtk.vtkImageReader()
        Image=vtk.vtkImageData()
        TIFFReader.SetFileName(self.ImgName)
        TIFFReader.Update()#Here I'm using the TIFFReader to extract 
pertinent info from the file
        DataExtent=TIFFReader.GetDataExtent()
        Reader.SetDataExtent(DataExtent)
        Reader.SetDataScalarTypeToUnsignedChar()#This is an 8-bit image 
w/ one scalar (0-255 greyscale)
        Reader.SetNumberOfScalarComponents(1)
        Reader.SetFileName(self.ImgName)# I use the vtkImageReader 
because the TIFF reader yields different results on Windows and Mac
        Reader.Update()
        self.ImgData=Reader.GetOutput()

    def RenderImage_8bit_LUT(self):
        import vtk
        #************************************
        BW_LUT=vtk.vtkLookupTable() #We must use a lookup table to map 
the scalar values to HSVA colors for display
        BW_LUT.SetTableRange(0,255) #Sets range of values for our 8-bit 
unsigned char scalars
        BW_LUT.SetSaturationRange(0,0) #Sets saturation range between 0 
and 1 (0 for greyscale)
        BW_LUT.SetHueRange(0,0) #Sets hue between 0 and 1 (0 for black 
and white)
        BW_LUT.SetValueRange(0,1) #sets value range between 0 and 1--we 
use whole range for greyscale here
        BW_LUT.Build()#Don't forget to build the LUT
        #************************************
        LUT_Mapper=vtk.vtkImageMapToColors()#Now we have to map the LUT 
to the data
        LUT_Mapper.SetInput(self.ImgData) #Gets output from image reader 
for mapping of scalars
        LUT_Mapper.SetLookupTable(BW_LUT) #Sets the lookup table we wish 
to use
        LUT_Mapper.Update() #Update for good measure--probably not nessacary
        #************************************
        BW_Viewer=vtk.vtkImageViewer() #We can use vtkImageViewer to see 
if our data looks right
        BW_Viewer.SetColorLevel(125)#In medical imaging, the color level 
specifies the median value
        #for the LUT ramp--changing this value effects contrast in 
different parts of the histogram
        BW_Viewer.SetColorWindow(255)#The color window specifies the 
width of the range of values to
        #be used; the default values for color level and color window 
will not work very well with our data
        #************************************
        BW_Viewer.SetInput(LUT_Mapper.GetOutput()) #get the LUT mapped 
data to be viewed
        BW_Viewer.Render() #Hopefully this renders the image...

if __name__ == '__main__':
    import os
    TstImage='series27/series27_Series027_z003_ch02.tif'
    devel_path=('/Workspace/Developement/Python/LeicaFileProject')
    os.chdir(devel_path)
    MyTiff=ImageRdDsply(TstImage)
    MyTiff.RenderImage_8bit_LUT()

-- 
Karl Garsha
Light Microscopy Specialist
Imaging Technology Group
Beckman Institute for Advanced Science and Technology
University of Illinois at Urbana-Champaign
405 North Mathews Avenue
Urbana, IL 61801
Office: B650J
Phone: 217.244.6292
Fax: 217.244.6219
Mobile: 217.390.1874
www.itg.uiuc.edu




More information about the vtkusers mailing list