Page moved to: Pythonpixels

A few days ago, I wrote Pythonpixels, an original interface for image processing. (Download).

Let's say you want to quickly prototype a new imaging algorithm. As a simple example, you are increasing the Red channel of an image by 40. Typically, this would first involve quite a bit of code, in order to gain pixel-level access to the image. Also, once testing your project, you would need to set up a test framework and enter the debug/recompile cycle.

With Pythonpixels, this whole process is as easy as typing
map:
    R=r+40
Lower-case "r" means the old red value, and "R" means the new red value. That's all there is to it. To test the effect, type this into a box, press Run, and you see the results instantly.

If you wanted to create a gradient,
loop:
    R=x+y
    G=x-y
    B=0
(It's fun to experiment making patterns this way. In the examples that come with Pythonpixels, I played around with sin and cos as well to make funky patterns.)

Also, what you type is interpretted as Python code. (Any value > 255 or < 0 is truncated for you). So, you can include complicated logic, and read the output from print statements.

If you want to do something more advanced, the entire image is exposed as imgInput. The following example makes your image all wavy.
from math import sin, cos, atan2, sqrt, pi
midx = width/2
midy = height/2
nwave = 12
imgOutput = ImageChops.duplicate(imgInput)
imgInputArray = imgInput.load()
imgOutputArray = imgOutput.load()
twopiconst = 2.0 * pi / 128.0
loop:
    newx = x + nwave*sin( y * twopiconst)
    newy = y + nwave*cos( x * twopiconst)
    if (newy>0 and newy<height and newx>0 and newx<width):
        imgOutputArray[x,y] = imgInputArray[newx,newy]


Or hue shift:
loop_hsl:
    H=h+0.2


It comes with other effects, including convolution matrices, fractals, kaleidoscope, and posterize. Data-oriented operations work very well, too, like finding pixel values, statistics, or making a histogram. Other features include pasting an image from the clipboard and batch-processing a folder of images.

Try it out! Windows Download (3.7Mb, GPL). Unzip the file and run Pythonpixels.exe. Let me know what you think, and show me scripts you come up with.

Source Python 2.5 (GPL). Requires packages tkinter, python-imaging (PIL), python-imaging-tkinter (ImageTK).

You can check out the source. 2013 Edit: moved to Downpoured at GitHub!



More details: The keyword "loop" loops through every pixel, (providing the variables x and y), and if you assign to R, G, or B, the output value at that position will be changed.

The keyword "map" sets up a precomputed table for red, green, and blue values. This makes the effect very fast, but limits what can be done - the effect cannot depend on x,y position, and hsv or hsl cannot be used.

"loop_hsv" and "loop_hsl" work in the same way as loop but are in different color spaces.