[vtk-developers] VTK-Python: Numeric Array <-> ImageData.

David Gobbi dgobbi at imaging.robarts.ca
Sun Dec 8 16:06:10 EST 2002


Hi Prabhu,

Thanks for the work.  Here are some comments:

1) Since vtkConstants.py contains the same constants of
   vtkSystemIncluces.h, maybe the vtk/__init__.py should
   do a "from vtk.util.vtkConstants import *" so that people
   automatically have access to these constants (just like
   they do in C++)

2) There are a whole bunch of missing calls to 'UpdateInformation'
   in vtkImageExportToArray (these were also missing in the original
   code) before calls to GetWholeExtent() etc.

3) Testing on multiple files doesn't make the test more rigorous,
   the important thing is to have one test per data type (or
   at least the most common types: unsigned char, short, unsigned short,
   float) and a test for multiple components.

   At minimum the tests should include: 1 test on unsigned char greyscale,
   1 test on short greyscale, 1 test on unsigned char color

It would also be nifty if it checked for Numeric versions greater than 20
and did the direct array->void* trick that Berk mentioned instead of
wasting memory by converting to a string first.

 - David

On Sun, 8 Dec 2002, Prabhu Ramachandran wrote:

> 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
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at public.kitware.com
> http://public.kitware.com/mailman/listinfo/vtk-developers
>




More information about the vtk-developers mailing list