Baby steps with Pancito: a simple color filter

20Jan07

I was thrilled to find out about Pancito today, a simple-to-use Haskell library for functional image manipulation. In Pancito, images are functions from a Point datatype to a Colour type. Slow, but fun.

As a quick showcase, this is a simple color filter in Pancito:

module Main where
import Pancito2
import Colour
import Common
import Point
import Reprocess
import System
 

jamma j c = rgba  ((r c)/j) ((g c)*j) ((b c)**j) (a c)

getImg fn = readPpm fn square01 white;
writeImg fno func ws im =  ppm square01 ws  fno (func .  im);

main = do { [fn, fno, j]<-getArgs; y<-getImg fn ; writeImg fno (jamma (read j)) (snd y) (fst y); putStr $ "Applied " ++  j ++ "-level Jamma filter to "++fn++"; written to "++fno;}

For convenience, I also wrote a quick shell script that handles conversion from JPEG to PNM and back with NetPBM, and opens original and altered image on OS X’s Preview.

echo "1. Converting JPG to PNM…"
jpegtopnm $1 > t1.pnm
pnmtoplainpnm t1.pnm > t2.pnm
echo "2. Running Jamma plugin.."
./jamma t2.pnm t3.pnm $3
echo
echo "3. Converting back to JPG .."
ppmtojpeg t3.pnm > $2 && open $2 && open $1

This is all a horrible hack, but I’ve only worked in this for half an hour and I’m excited enough to want to share immediately. Here’s a picture of my hand:

original after jamma
manito.jpg manito2.jpg

Here’s a NSFW classic in original.jpg and jammaed version.

Sure, from a Haskell viewpoint this isn’t really *that* exciting — it’s all rather simple — but I’m very fond of image manipulation, and wrote 30% of a Pancito-type library before dropping it. I might just be excited that someone went through the end of it. It’s at the very least a good framework for image processing research.

About these ads


No Responses Yet to “Baby steps with Pancito: a simple color filter”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: