Image filters

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2009   #1
Image filters

Hey I am looking for more information about the algorithm used in the standard imaging filters such as multiply , burn, dodge etc...
Can anyonme suggest me some programming, math or books on this topic.
 
Old 10 October 2009   #2
The basic blend modes (multiply, burn, dodge, lighten, darken etc.) are all pretty simple local operations on two layers of color. So basically, all you need is a blend function, and to use it on all pixels in your resulting image.

Basic C code with all the blend modes can be found here: LINK

If you have a basic understanding of C, this should really be enough.
Feel free to ask if you need further guidance.

Tamir.
__________________
Ha ha!
Programming again.
 
Old 10 October 2009   #3
Cool Thanks. Thats what I was looking for.
 
Old 10 October 2009   #4
multiply = a x b
darken = min (a,b)
lighting = max (a,b)
linear dodge = a + b
 
Old 10 October 2009   #5
PDF reference describes this.
http://www.adobe.com/devnet/pdf/pdf_reference.html
 
Old 10 October 2009   #6
When blending two layers with a Blending Mode and Opacity, there are two steps:

1. Generate the Blending Layer using a Blending Mode (Multiply, Divide, etc).
This is done by mixing the Background Layer with the Foreground Layer using a Blending function.

2. Combine the Blending Layer with the Background Layer using a Combine function (most usually MixOpacity).

I implemented Blending functions and Combine functions for colors defined by 4 unsigned chars from many resources (including the links above), and I created a single header -mix.h - that can be used anywhere.

Here is an example of how to combine two colors to get the same result as PhotoShop with two layers with alpha, a Multiply blending mode and an Opacity of 50.0.


#include "mix.h"

unsigned char bg[4] = { 180, 70, 70, 255 };
unsigned char fg[4] = { 80, 70, 175, 128 };

unsigned char opacity = 128; (50%)

unsigned char dest[4] = { 0, 0, 0, 0 };

Multiply( dest, bg, fg ); // Blend bg and fg -> dest
MixOpacity( dest, bg, dest, opacity ); // Combint bg and dest -> dest


All this stuff is implemented by the Texture Painting tool for CrackArt, so you can download the full source code and check it out.
 
Old 10 October 2009   #7
I know others have already answered the question, but I've always found the following site to be a good description of each blending mode:

http://www.pegtop.net/delphi/articles/blendmodes/

Cheers,
Michael
 
Old 11 November 2009   #8
I have a question on the related subject. Given two RGBA colours c1 = {r1, g1, b1, a1} (top) and c2 = {r2, g2, b2, a2} (bottom), I want to find the resulting colour cr = {r, g, b, a} when both colours are composited using the 'Normal' mode algorithm.

The algorithms I managed to find, seem to assume that the bottom colour has an opacity of 255 (fully opaque), but what if it doesn't?

After some experimentation, I figured that the resultant opacity can be calculated by:

a = (255 - a2) / 255 * a1 + a2;

Could anyone please tell me how I can find the other three colour components?

Thank you
 
Old 11 November 2009   #9
From what I find in PDF spec:

a_r * C_r = ((1-a_1) * a_2 * C_2) + ((1-a_2) * a_1 * C_1) +
 (a_2 * a_1 * B(C_2, C_1))


where
a_? - alpha for resulting (r), top (1) and bottom (2) layers
C_? - color, accordingly
B() - blend function

in this case (normal mode):
B(C_2, C_1) = C_1
, so
a_r * C_r = ((1-a_1)*a_2*C_2) + ((1-a_2)*a_1*C_1) + (a_2*a_1*C_1) =
 ((1-a_1)*a_2*C_2) + a_1*C_1
  
 
Old 11 November 2009   #10
Thank you wobagi, it worked fine. Also, after having a look at that reference PDF, it seems to be very useful.
 
Old 11 November 2009   #11
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:49 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.