[vtkusers] ImageReader Mystery

dean.inglis at camris.ca dean.inglis at camris.ca
Sun Oct 19 15:54:38 EDT 2003


John,

looking at your python code, there may be a couple of
small but important details to consider:

*********************************************************
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)
*********************************************************

The data extent is usually of the form:

0,NColumn-1,0,NRow-1,0,NSlice-1

so is your above code correct?

The Shiftscale filter may need to be corrected:

********************************************************
# 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()
*******************************************************

This is ok as long as scalarmin is 0.  For
best results do the following:

intercept = -scale*scalarmin
trueshift = intercept/scale
shiftScale.SetOutputScalarTypeToUnsignedChar()
shiftScale.SetShift(trueshift)
shiftScale.SetScale(scale)
shiftScale.SetInput(reader.GetOutput())


Dean




More information about the vtkusers mailing list