[vtk-developers] VTK-Python: Numeric Array <-> ImageData.
Prabhu Ramachandran
prabhu at aero.iitm.ernet.in
Sun Dec 8 12:46:10 EST 2002
hi,
Just committed some new and old code to VTK CVS and I need some help.
I've added the following to Wrapping/Python/vtk/util/
vtkConstants.py, vtkImageExportToArray.py and
vtkImageImportFromArray.py
These files were originally in VTK 3.2 and written by David Gobbi.
I've updated them to VTK 4.x. That required a few lines of change
here and there. I did however test it quite a bit to my limited
knowledge.
I've also added a test for the vtkImage*Array.py code here:
Imaging/Testing/Python/TestNumericArrayImageData.py
Run it like so:
vtkpython TestNumericArrayImageData.py -B $VTK_DATA_ROOT/Baseline/Imaging
It tests the code by first exporting a PNG image to a Numeric Array
and then converts the array to an image and compares that image to the
original image. It does this for all PNG images in a particular
directory. So AFAIK it is fairly rigorous since it passes (zero
threshold) on all the images in Baseline/Imaging. Takes a while
though (~7 secs on a PIII 450).
I have not setup the Testing/Python directory to include the tests in
the nightly regression tests because I have a couple of questions.
1. The test obviously requires Numeric to be installed. Right now I
fail the test if Numeric is not installed (I print a message saying
Numeric is necessary). Is this OK or should I pass the test (ugh!)
and print the message alone? I really would appreciate advice on
this. I think most folks using VTK-Python will use Numeric so its
not too much to ask for a Numeric install. However do all the
machines that test VTK-Python have Numeric installed?
2. While testing the code I ran into problems with vtkPNGReader. I
was doing something like this:
reader = vtk.vtkPNGReader()
for i in bunch_of_png_images:
reader.SetFileName(i)
reader.Update()
# use reader.GetOutput()
And I had lots of trouble with this. Basically after a few tests
passing it would segfault! I fixed the error by simply instatiating
the vtkPNGReader each time inside the loop. So unless I don't know
something about the reader this is a bug. I looked at the
vtkImageReader2.cxx code for SetFileName and it seems to read ok.
Anyone have clues on this?
I'd very much appreciate comments. If my first question is cleared up
I can make it so that the nightly tests run this test also.
David, are the tests adequate? I don't know enough about the imaging
pipeline to do a good enough job but I guess the present test is a
start. Feel free to add more. :)
Thanks,
prabhu
More information about the vtk-developers
mailing list