[vtkusers] ImageReader Mystery
John Vard
jvard at tcd.ie
Thu Oct 16 07:20:57 EDT 2003
Dear Users
I'm having a problem reading raw image files. Out of 10 differing images, 3
decide to render while the reminder appear as rendered white canvases. I've
looked at the problem systematically using Kitware's application ParaView as
a means to test the quality of the problematic files. ParaView opened the
files and henced validated the file quality. Next I looked at the scalar
ranges which from file to file are similar enfact files that fail to open
often contain scalar ranges identical to those that render. Finally the
reader appears to be working as rendering via a viewer works??
Currently I'm all out of ideas.. I've attached my code below and would
appreciate some help on this (odd) problem..
from vtkpython import *
os.chdir("<raw file directory>")
reader = vtkImageReader2()
reader.SetFileName("<file.raw>")
reader.SetDataScalarTypeToUnsignedShort()
reader.SetDataByteOrderToLittleEndian()
reader.SetDataSpacing(<Pix_SpacingX>,<Pix_SpacingY>,1.0)
reader.SetDataExtent(0,<Column>,0,<Row>,0,0)
data = reader.GetOutput()
data.Update()
# Determine image scalar range
scalarmin,scalarmax = data.GetScalarRange()
print scalarmin,scalarmax
scale = 255/(scalarmax-scalarmin)
shiftScale = vtkImageShiftScale()
shiftScale.SetInput(reader.GetOutput())
shiftScale.SetShift(0)
shiftScale.SetScale(scale)
shiftScale.SetOutputScalarTypeToUnsignedChar()
#Setup Actor
ia = vtkImageActor()
ia.SetInput(shiftScale.GetOutput())
# Create the RenderWindow, Renderer
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
#initiate window interactor
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
#iren.SetInteractorStyle(None)
#Add Actor to Render and set Win size
ren.AddActor2D(ia)
renWin.SetSize(400, 400)
iren.Initialize()
renWin.Render()
iren.Start()
--
Regards
John Vard
Trinity Centre for Bioengineering
Mechanical Engineering Dept.
Trinity College
Dublin 2
Ireland
More information about the vtkusers
mailing list