[vtkusers] Re: ImageReader Mystery
John Vard
jvard at tcd.ie
Thu Oct 16 09:57:58 EDT 2003
I've noticed that all the files that open have a Pixel Spacing of 0.15 while
those that don't have a spacing of 0.2.... Can anyone explain this ??? Odd...
On Thursday 16 October 2003 12:20, you wrote:
> 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 (python scripted)
>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
e-mail: jvard at tcd.ie
www.biomechanics.ie
More information about the vtkusers
mailing list