Feb 27, 2007

Building a Cocoa application using a custom Core Image filter (introduction)

A couple of months ago, some members of my team were working on a facial recognition project for one of our customers. One thing they were trying to do was to determine if filtering the images in various ways could improve the recognition algorithm.

They were implementing their system in Java, but I immediately thought that Core Image would make their job much faster, since we could offload the image processing to the graphics cards on our Mac Pros rather than writing the algorithms in Java.

If you are not familiar, Core Image is Apple's image processing framework which can provide very high performance image processing by offloading the work of image processing to the graphics card. Core Image includes a huge number of image filters (just check out the list on the Apple web page).

The test system applied a sequence of image convolution filters to images with varying coefficients and then submitted the filtered images to the recognition system where they would be scored. We iterated over different combinations of filters to find a way to improve the scoring of the algorithm in general.

I was surprised to discover that Apple did not include a convolution filter by default. Convolution is the "jack of all trades" of image processing algorithms and can be used for all sorts of things like edge detection, sharpening, blurring, noise reduction, and so on, depending on the coefficients used.

This meant that I would have to develop my own custom image unit that performed convolution. This seemed like it might be a difficult task, but it turned out to be much easier than I expected. Along the way I learned a lot more about Quartz Composer, programming using the Open GL shading language, Cocoa Bindings, and creating custom image units on Mac OS X.

Over the next several posts I'll step through the development process to a working sample Cocoa application that allows you to apply convolution to any image.


SubstanceMX said...

Man, Im glad of your blog about CIFilter wich helped me trying to understand (after tutorials failure).

You said that you were buiding a facial recon proyect using this, Im doing a motion tracker and there is something just dont catch: how did you get the image processing information, the data from the CIFilter for such facial recon?

BTW Im little new on cocoa.
Have a nice day!

Paul Franceus said...

Glad I could be helpful.

We had a facial recognition algorithm that already existed. What we were trying to do was to filter images in various ways and try to improve the accuracy of the recognition algorithm.

I wrote a server which used CIFilters to apply filters to images and we would send them to the algorithm to be scored. Another member of my team was using a machine learning algorithm to determine what coefficients to set for the filters. I wasn't exactly doing facial recognition with core image.

For a motion tracker I'd imagine that you would have two frames as input and output would be an image that showed where the motion was, right? you can have two different images as input and one as output, no problem.