cat /dev/brain/rand > /srv/tumblr

Mar 20 2011

Adjusting image contrast

I wanted to do some simple image manipulations under Plan 9 for my photographs. I don’t like to edit my images much and prefer to keep them close to what the camera produces. Thus, I don’t really need many operations, only resizing and image contrast enhancement. The former is already available in Plan 9 with the resample program, but I couldn’t find anything to do the latter.

Here’s a program to do image contrast enhancement through histogram stretching:

This is pretty similar to the autolevels command available in photoshop/gimp, with a default of 1% clipping on the shadows and 0.5% on the highlights. Input/output is via stdin/stdout, and the program reads/writes Plan 9 image format so it forms part of a pipeline. Here’s an example invocation:

    jpg -t9 input.jpg | resample -x 1000 | relevel -h 0.01 | topng > output.png

or with djpeg/cjpeg:

    djpeg -scale 1/4 input.jpg | ppm -t9 | relevel | toppm | cjpeg > output.jpg

Page 1 of 1