Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] matrix image filtering

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Jun 2010 19:34 Edited at: 7th Jun 2010 23:22
Through a simple equation as used by Photoshop, now you can use the following code to create all sorts of image filters without the need for specific code for each one. If you used Photoshop before, then perhaps you've seen the custom filter dialog which displays a 5x5 grid of numbers. The link below explains it and the code implements it.

http://ian-albert.com/graphics/customfilters.php



Example screen shot of the "emboss" filter



"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke

Attachments

Login to view attachments
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Jun 2010 22:45 Edited at: 1st Jun 2010 22:45
I'm probably just nagging, but anyway:

The gaussian blur kernel actually looks like this:



A gaussian blur is so famous because it has very nice properties a programmer can use:
* It can be split into several smaller kernels
* It can be split into a horizontal and a vertical pass
eg. the kernel here is actually [1 4 6 4 1]' * [1 4 6 4 1]

and if you're using the Pascal's triangle (binomial coefficients) as an approximation to a Gauss curve, then the sum of your kernel elements, or even the sum of the separate vector elements is a power of 2 which is easy to divide by.

Another thing I'd like to mention is that you forgot to cap your color components. You can't really see it in your example, but if you use the darken kernel to brighten up your image (center kernel value to 3 and filter scale to 1 or something) you can clearly see strange colors due to components exceeding the 0-255 range.

Nonetheless, nice code ^^

Cheers!
Sven B

Darker Flare
13
Years of Service
User Offline
Joined: 1st Jun 2010
Location:
Posted: 1st Jun 2010 23:28
I tried to do the Code from the first post, it says "The command is invalid." What is this meanin' caus I'd like to know, thanks!

Game making, game modding.
Doing both just saves time!
-DF
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Jun 2010 23:25
Good to know Sven, I've updated the code to reflect the real gaussian.

Quote: "Another thing I'd like to mention is that you forgot to cap your color components. "


As long as the scale and offset are correct, the colors shouldn't go out of range on anything other than trying to brighten the image as far as I could tell. And technically, there's a better equation for adjusting the light amplitude of an image anyway.

Darker Flare, what command is it saying is invalid?


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 8th Jun 2010 13:32
Phaelax added this bit of code to what you had to set the blending mode, some modes make it look very good. Put the code in after the print fps bit.



Dark Physics makes any hot drink go cold.

Login to post a reply

Server time is: 2024-03-28 10:05:17
Your offset time is: 2024-03-28 10:05:17