Mar 1, 2007

Cocoa application with custom Core Image filter 1: What is image convolution?

Before I delve into development of my Core Image kernel, I think I would like to give a quick description of image convolution. There are plenty of resources on the internet that already describe the mathematics of this procedure in great detail, such as Image Processing Fundamentals - Convolution-based Operations. A Google search will reveal a wealth of information.

While it's easy to get lost in the mathematics, performing an image convolution filter is a relatively simple operation. Basically you apply a multiplier to a matrix of pixels surrounding each destination pixel and add them all together. The result of this operation is the new value of the pixel at the center. For the purposes of these articles, we will be sticking with a simple 3x3 matrix, but there is no reason why you can't perform this type of filtering with larger matrices.

Here are some examples of 3x3 convolution applied to an image:

This first example shows an edge detection algorithm

This second one shows a sharpness kernel.
I find the easiest way to think about this is that the coefficients provide the weight that that particular pixel contributes to the final result. If you are interested in interactively exploring this concept, I recommend this site: Molecular Expressions Microscopy Primer: Digital Image Processing - Convolution Kernels - Interactive Java Tutorial. It's got some great interactive tutorials.

In the next post I'll build the Core Image kernel using the OpenGL shading language.

1 comment:

SubstanceMX said...

Hi Paul. With a very short time to thankyou for your answer last time, but these days have been of reading a lot and understanding a little (by now im a barelly 3 months beginer and very urged to catch the idea). At least my cameras controller and the CIFilters are working perfect without those memory leaks already fixed last day and night.

Probably you already know this link, but could be a good update to this subject about the convolution kernel and kernel programming. Its about real-time image procesing using vImage functions and provides another idea of what to do (of course still being stydied by me):
I hope the link survive a time because a lot of links to the developer page are going broken last days.

Ill comment about this in my own blog in another time.

Have a nice day!