Beginning with Pillow, the PIL Fork (Python Imaging Library)

Article index:

5 – Image Processing

With Pillow, you can easily apply common image filters: blur, emboss, sharpen, etc. Just import the ImageFilter module:

from PIL import Image
from PIL import ImageFilter

im0 =

#im = im0.filter(ImageFilter.BLUR)  
#im = im0.filter(ImageFilter.CONTOUR)  
#im = im0.filter(ImageFilter.DETAIL)  
#im = im0.filter(ImageFilter.EDGE_ENHANCE)  
#im = im0.filter(ImageFilter.EDGE_ENHANCE_MORE)  
im = im0.filter(ImageFilter.EMBOSS)  
#im = im0.filter(ImageFilter.FIND_EDGES)  
#im = im0.filter(ImageFilter.SMOOTH)  
#im = im0.filter(ImageFilter.SMOOTH_MORE)  
#im = im0.filter(ImageFilter.SHARPEN)  

This code sample gives us the opportunity to show how to convert the image data to a format suitable for fast texture update. The Pillow image object has a function called tostring() that returns a kind of raw buffer containing the pixmap. GLSL Hacker uses this raw buffer to update its OpenGL textures like shown in the following code snippet:

tex01 = moon3d.image.create2dRgbU8(imageW, imageH)
moon3d.image.updatePixmap(tex01, im.tostring())

The full demo is available in moon3d/gl-210-python-pil-pillow/pillow_image_processing.xml. Just load it in GLSL Hacker and you should have:

GLSL Hacker, Pillow (PIL fork) image processing, EMBOSS, Python

Article index:

Pages: 1 2 3 4 5 6 7

[ Subscribe to Geeks3D latest news by email ]

↑ Grab this Headline Animator