I’ve been having a look at the CoreImage Kernels on OS X recently. They are a powerful tool, and you can quickly write a small kernel to edit an image in a very specific way. You can then use Quartz Composer to test that your kernel does what you thought it should. Unfortunately once you have done this there is no apparent way to save the output of Quartz Composer. To solve this issue I have written a small command line program which takes a path to your kernel, a series of inputs, and an output file path, and applies the kernel. The source code for this is here.

So I have a CIKernel file that I have tested with Quartz composer like this:

/* A CoreImage kernel to remove saturated values. */
kernel vec4 coreImageKernel(sampler image, float comparison)
{
vec4 colour = sample(image, samplerCoord(image));
float maxCol = compare (colour[0] - colour[1], colour[1], colour[0]);
maxCol = compare (maxCol - colour[2], colour[2], maxCol);
float minCol = compare (colour[0] - colour[1], colour[0], colour[1]);
minCol = compare (minCol - colour[2], minCol, colour[2]);
vec4 compareVec = vec4 (maxCol - minCol) - comparison;
vec4 clearCol = vec4 (0.0);
return compare (compareVec, colour, clearCol);
}

This removes the high saturation values from the image leaving only the grey scale colours. To apply this to an image I write:

./ApplyCIKernel ~/Desktop/removeSat.cikernel Image ~/Desktop/JamesPicture.png float 0.05 ~/Desktop/output.png

This applies the CIKernel removeSat.cikernel with an Image arguement and a floating point argument, and writes the result to the path ~/Desktop/output.png. The arguments must match the arguments of your CIKernel (samplers replaced with images). It doesn’t parse the kernel definition to work out what types it should take so you need to tell it the types.

So in this example the input image looked like this:

and the output looks like this:

In this case the colour is replaced by a clear colour, so you can see background of the website through the person.

The program doesn’t handle relative paths (but it will handle tildes).