[Paraview] Paraview python script: passing images to PIL (python image library)

David E DeMarle dave.demarle at kitware.com
Wed Oct 12 13:55:35 EDT 2016


Look into the cinemaIO directory of ParaView. We move back and forth
between paraview, numpy and PIL often there.

For example:
image = self.view.CaptureWindow(1)
ext = image.GetExtent()
width = ext[1] - ext[0] + 1
height = ext[3] - ext[2] + 1
imagescalars = image.GetPointData().GetScalars()
idata = numpy_support.vtk_to_numpy(imagescalars)
image.UnRegister(None)
imageslice = idata.reshape(height, width, 3)
imageslice = numpy.flipud(imageslice)
pimg = PIL.Image.fromarray(imageslice)

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909

On Wed, Oct 12, 2016 at 1:42 PM, Albina, Frank <frank.albina at sauber-
motorsport.com> wrote:

> All,
>
> A simple question: my incentive is to manipulate images using PIL in a
> pvbatch script. At the time being, I am writing the images to file in PNG
> format and reading the file again from disc using PIL. I have found out
> that the underlying image writing is performed by the vtkPNGWriter class
> and that this class allows to write to memory (vtkPNGWriter.SetWriteToMemory).
> Hence my question: Is it possible to “write” a PNG file to memory so that I
> can  process it further using PIL? If so, how shall I proceed?
>
> Thank you very much in advance.
>
> Cheers,
>
> Frank.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensou
> rce/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/paraview
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20161012/bb04b097/attachment.html>


More information about the ParaView mailing list