Image filters

Become a member of the CGSociety

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

Thread Tools Display Modes
  10 October 2009
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.
  10 October 2009
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.

Ha ha!
Programming again.
  10 October 2009
Cool Thanks. Thats what I was looking for.
  10 October 2009
multiply = a x b
darken = min (a,b)
lighting = max (a,b)
linear dodge = a + b
  10 October 2009
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.
  10 October 2009
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:

  11 November 2009
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
  11 November 2009
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))

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
  11 November 2009
Thank you wobagi, it worked fine. Also, after having a look at that reference PDF, it seems to be very useful.
  11 November 2009
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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
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
Society of Digital Artists

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

All times are GMT. The time now is 06:12 PM.

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