What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Average colour blend mode?


noff

New Member
Messages
3
Likes
0
I have 10 layers and I want to blend them such that the resultant flattened image represents the average colour. i.e. If layer 1 has a white pixel and layers 2-10 have black pixels the result will be 90% black.

What is the best solution?
 

Inkz

Guru
Messages
2,358
Likes
1,554
I think you may need to be a bit more specific with your question....

I personally have no clue as to what you are asking.
 

noff

New Member
Messages
3
Likes
0
I think you may need to be a bit more specific with your question....

I personally have no clue as to what you are asking.

Fair enough!

For simplicity assume it's a 1X1 pixel image with 10 layers each with a different colour. I want to flatten this image such that the result has a value of the average of the 10 layers. i.e. RGB or CMYK values are all added and then divided by the number of layers.

Is that easier to understand?
 

dv8_fx

Retired Administrator
Messages
13,761
Likes
4,789
Same here... I don't get it or what you intend to do with it.

But rather than 10 layers, 2 - a black layer over white , lowering the opacity of black by 10% and flattening the image gives you 90% black. Even the reverse ... white over black - lowering the opacity of white by 90% gives you 90% black.

Even if you use other colors - Red, Blue, Green (3layers) or Cyan , Yellow , Magenta , Black (4 layers} and lowering the opacity of any combination of layers will give you a full spectrum of color.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
The answer that is always given is that the bottom layer should have an opacity of 1, the next one up an opacity 1/2, and so on till you get to the top layer which would have an opacity of 1 divided by the number of layers.

This seems to work well enough in practice, but I've never derived it myself. I have a suspicion that it may have limitations (eg, only works in the limit of a large number of layers, or something similar), and it may be dependent on the 2.2 (or whatever) gamma encoding of the data. I've needed a prod like this. If I get a chance, I'll look into it.


Tom

PS - note change in the formula. I typed it up without thinking.
 
Last edited:

SCTRWD

Power User
Messages
457
Likes
239
There is nothing complicated about average. The formula is simple:
100/N,
where N is the position of layer. That is: the first layer -(the bottom one) - 100%
the second - 100/2 = 50%
the third - 100/3 = 33,3%
the fourth - 100/4 = 25%
the fifth - 100/5 = 20%
and so on...

This is classic. But you can, of course, do it modern way: simply select your layers, turn them to Smart Object and choose Layer->Smart Objects->Stack Mode->Mean.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
There is nothing complicated about average.

Yes, your formula is identical to the common one that I already stated, but are you really sure that the issues I mentioned in that post, particularly the gamma encoding concern, don't arise? Obviously, averaging light intensity (what I suspect the OP wants to do) is not the same as averaging gamma encoded light intensity (ie, what the cited formula accomplishes).

Have you ever seen a derivation or serious discussion of the formula?


Tom M


PS - Your suggestion to simply use the stack-mean functionality is excellent. I use stack-median approach to removing moving objects relatively frequently, but I've been doing the average so many years the old 1/N way, it never occurred to me that I could simply change from median to mean. :)
 

SCTRWD

Power User
Messages
457
Likes
239
Have you ever seen a derivation or serious discussion of the formula?

Derivation is simple. Once you know the opacity math:

Result = Layer1*(1-a) + Layer2*a

, the formula for average can be derived easy:)

Sorry, but I did not notice any reference to gamma issues in OP posts... Not that I still see the relevance of it ...

PS - Your suggestion to simply use the stack-mean functionality is excellent. I use stack-median approach to removing moving objects relatively frequently, but I've been doing the average so many years the old 1/N way, it never occurred to me that I could simply change from median to mean. :)

Long, very long time ago I used 1/N way to get decent scans. Back in those days scanners were something "color noisy", so I had to do several scans and use the formula to get rid of those RGB outliers:)
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Derivation is simple. Once you know the opacity math:
Result = Layer1*(1-a) + Layer2*a
, the formula for average can be derived easy

Actually, I think you would have a hard time deriving it from that formula. ;-) . The reason is that you made a slight error in the 1st term. The 1st term in your recursion should involve the result coming "through" the layer immediately below, not just the value of that layer.

I would put it as shown below. Then all is well. :)

layer_blending_equations.jpg

etc.

Cheers,

Tom
 

SCTRWD

Power User
Messages
457
Likes
239
Actually, I think you would have a hard time deriving it from that formula. ;-) . The reason is that you made a slight error in the 1st term. The 1st term in your recursion should involve the result coming "through" the layer immediately below, not just the value of that layer.

Man, I did not write no recursion. I wrote general opacity formula. It's when you use this formula for recursion you naturally end up with cumulative result:)
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Hi SCTRWD - You're right, I shouldn't have called your formula a "recursion" -- it didn't even have indices. I should have simply called it a "formula" and left it at that. I was being generous because it was obvious that you were on your way to attempting to derive (or guide people to derive) a true recursion formula.

However, the real problem is not nomenclature, but is that your formula is only correct for the special case of the 1st and 2nd layers in the stack. This is because "the result" above the 1st layer only involves "the value" of the 1st layer. However, for all layers above the 1st, "the result" above the topmost layer involves both "the value" of the topmost layer and "the result" of all layers below, NOT simply "the value" of the layer immediately below, as your formula suggests.

That being said, it's clear that the famous 1/n opacity method is exact for any number of layers.

Cheers,

Tom M
 

SCTRWD

Power User
Messages
457
Likes
239
Hi SCTRWD - You're right, I shouldn't have called your formula a "recursion" -- it didn't even have indices. I should have simply called it a "formula" and left it at that. I was being generous because it was obvious that you were on your way to attempting to derive (or guide people to derive) a true recursion formula.

Oh man, I derived that recursion formula many years ago....

However, the real problem is not nomenclature, but is that your formula is only correct for the special case of the 1st and 2nd layers in the stack. This is because "the result" above the 1st layer only involves "the value" of the 1st layer. However, for all layers above the 1st, "the result" above the topmost layer involves both "the value" of the topmost layer and "the result" of all layers below, NOT simply "the value" of the layer immediately below, as your formula suggests.

Tom, stop explaining obvious things, please. I knew that fo ages. Layer1 in my formula is aggregated result of all the layers beneath Layer1 including Layer1 itself.
 

Paul

Former Member
Messages
12,879
Likes
7,023
Ok guys let's take a step back/breath and start again.
Only this time without loosing our cools please, also maybe in layman's terms for the rest of us, as interesting as it is:mrgreen:
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Sorry if I'm "preaching to the choir", but I would bet any amount of money that most people reading your formula on this forum would be confused about when "LayerN" stands for the actual value of the layer, and when it stands for the aggregated result of everything below LayerN, since it's used one way in the first term in your formula and the other way in the 2nd term in your formula. Anyway, good discussion.

Cheers,

T
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Don't worry, Paul, sometimes nerds may sound like they are fighting, but then they go out for a beer and all is well cuz' they're really brothers under the skin. :)

As far as I'm concerned, the best method to average a bunch of layers is what was suggested by SCTRWD: Stack 'em and use the mean function.

Cheers,

T
 

SCTRWD

Power User
Messages
457
Likes
239
Sorry if I'm "preaching to the choir", but I would bet any amount of money that most people reading your formula on this forum would be confused about when "LayerN" stands for the actual value of the layer, and when it stands for the aggregated result of everything below LayerN, since it's used one way in the first term in your formula and the other way in the 2nd term in your formula. Anyway, good discussion.

Cheers,

T

It's just common way to describe Blend modes, opacities, adjustments, etc. everywhere in books and docs. Google blend modes and see yourself:)

I just reposted my own post from another forum http://www.photoshopforums.com/post84567.html#84567
 

Top