Next post: A creative way to turn formatted text into HTML

Raw Pixel Processor

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

Screenshot



Let's say you want to set the Red channel of an image to be the Green, but with 30 less lightness. Rather than having to write a lot of code to gain pixel-level access to an image, you can just write this (as seen above),
loop:
    G = r - 30
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'll see the results instantly. This is great for prototyping a new image effect.

You can also use the variables "x" and "y" so set colors based on the position of the pixel. If you wanted to create a gradient,
loop:
    R = x + y
    G = x - y
    B = 0
(See the examples for some interesting patterns generated this way). 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 use print statements to debug.

To shift the hue, use the HSL color space:
loop_hsl:
    H = h + 0.2


I've used PythonPixels to implement many effects, including convolution matrices, 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. 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. You can also use the "loop_hsv" and "loop_hsl" keywords.

Try it out -- there are more than 40 built-in effects! Windows Download (3.7Mb, GPL). There is no need to install, just unzip the file and run pythonpixels.exe.

2013 Update: the source code has been uploaded to GitHub here. Requires the packages tkinter, python-imaging (PIL), python-imaging-tkinter (ImageTK).