Custom Image Convolution Filters
The ability to create custom filters is a mainstay of any quality graphics application. A robust matrix-based filter engine can generate hundreds of unique effects by simply adjusting the matrices that get passed into the engine.
In this project, I’ve provided a 5x5 custom filter engine with support for scaling/weighting and biasing/offsetting. This is identical to the custom filter engine provided by Photoshop, and mine is even slightly faster (at least for the screen-sized images I’ve been testing).
Besides being fast, the engine is also smart. It is clever enough to estimate edge pixels correctly - even for scaled/weighted filters - and it will automatically validate all input values to make sure they’re appropriate.
Finally, I’ve included 7 sample filters for you to play with, including blur, sharpen, emboss, engrave, grease, unfocus, and vibrate. Below, you can see how each filter looks on a promotional image from the TV show Castle.
Original:
Blur:
Sharpen:
Emboss:
Engrave:
Grease:
Unfocus:
Vibrate:
Download the sample app and source code from GitHub
For a more advanced version of this tool, including auto-normalization for the divisor and offset values, you can see the source code for this function in my open-source photo editor, PhotoDemon. Here’s a screenshot of its Effects > Custom tool: