How do I manually stack photos for an equal average using given opacity levels?

  • Thread starter Thread starter LightningInAJar
  • Start date Start date
  • Tags Tags
    Photos
Click For Summary
To manually stack photos for an equal average using specified opacity levels, the opacity of each layer should be set to 100/n, where n is the layer number. This means that for four layers, the opacities would be 100% for the first layer, 50% for the second, 33% for the third, and 25% for the fourth. The discussion emphasizes that achieving equal representation of each layer requires careful calculation of contributions from each layer, particularly when stacking multiple images. The method is not just a math problem but also involves understanding how the layers interact visually. Ultimately, the approach ensures that each layer's contribution is balanced, allowing for a cohesive final image.
  • #31
LightningInAJar said:
Ok, finally figured it out. Top to bottom. I basically take the value of the percentage and divide by 100 to get 1 or less decimal and subtract from 1 to get opposite portion and multiply that by everything below it. At the end everything was 20% left.

20%
25%, 20%
33.3%, 26.66%, 20%
50%, 40%, 30%, 20%
100%, 80%, 60%, 40%, 20%
I agree although I could quibble about some details of how you stated it.
It might seem like magic that they all end up with 20% ( = 1/5).
IMO, it is easier to accept if you look at post #26 and notice how many factors cancel out.
Start with the whole thing, as you described it, with none of the multiplications or divisions calculated out:
##(1/5)L_5 + (4/5)( (1/4)L_4+(3/4)( (1/3)L_3+(2/3)( (1/2)L_2+(1/2)L_1) ) )##

Look at the last term above and cancel the multiply/divide by 2 to get this:
##(1/5)L_5 + (4/5)( (1/4)L_4+(3/4)( (1/3)L_3+(1/3)( L_2+L_1) ) )##
and combine the last two terms:
##(1/5)L_5 + (4/5)( (1/4)L_4+(3/4)( (1/3)(L_3+L_2+L_1) ) )##

Look at the last term above and cancel the multiply/divide by 3 to get this:
##(1/5)L_5 + (4/5)( (1/4)L_4+(1/4)( L_3+L_2+L_1 ) )##
and combine the last two terms:
##(1/5)L_5 + (4/5)( (1/4)(L_4+L_3+L_2+L_1 ) )##

Look at the last term above and cancel the multiply/divide by 4 to get this:
##(1/5)L_5 + (1/5)( L_4+L_3+L_2+L_1 )##
and combine the last two terms:
##(1/5)(L_5+L_4+L_3+L_2+L_1 )##

So every multiplier/divisor canceled out except the divisor for the highest level.
 
Last edited:
Physics news on Phys.org
  • #32
LightningInAJar said:
Ok, finally figured it out. Top to bottom. I basically take the value of the percentage and divide by 100 to get 1 or less decimal and subtract from 1 to get opposite portion and multiply that by everything below it. At the end everything was 20% left.

20%
25%, 20%
33.3%, 26.66%, 20%
50%, 40%, 30%, 20%
100%, 80%, 60%, 40%, 20%
What do these numbers represent?

For example, what exactly is line 3? Is that meant to be the opacities for 3 layers? It isn't.

While we're at it, what is line 1? Or 2?

The opacities should not be linear. You should get 100 50 33 25 20 17.
 
Last edited:
  • #33
LightningInAJar said:
Ok, finally figured it out. Top to bottom. I basically take the value of the percentage and divide by 100 to get 1 or less decimal and subtract from 1 to get opposite portion and multiply that by everything below it. At the end everything was 20% left.

20%
25%, 20%
33.3%, 26.66%, 20%
50%, 40%, 30%, 20%
100%, 80%, 60%, 40%, 20%
As Dave said, I don't know what these percentages are supposed to represent.
A single layer should be 100% opacity, not 20%.

The entire point of the opacities is that the 'light' from underlying layers gets absorbed partially by the layers above.

For a two layer stack: layer 1 loses 50% of its light as it passes through layer 2, because layer 2 has 50% opacity, which means it let's 50% of the underlying light through, and emits some quantity that's equal to that 50%. If we assume that layer 1 emits 100 units of light then 50 units will be absorbed by layer 2, the other 50 units will make it through, and layer 2 will emit another 50 units of light. The total light is then 100 units, with equal contribution from both layers. This makes the final image an average of the original two.

For three layers you have:
Layer 1 emits 100 units of light.
100*1/2 = 50 units after passing through layer two.
Since the opacity of layer 3 is 1/3 (the same as 2/3 transparency), this means that 2/3 of the light makes it through.
50*2/3 = 33 1/3 units from layer 1 makes it through 3.

Layer 2 emits 50 units of light.
50*2/3 = 33 1/3 units of light from layer 2 that makes it through layer 3.

Layer 3 emits 33 1/3 units of light. All of it makes it to the final image.

Each layer thus has equal amounts of 'light' make it through to form the final stacked image. This is again an average since each image has an equal contribution.
 
  • #34
DaveC426913 said:
What do these numbers represent?

For example, what exactly is line 3? Is that meant to be the opacities for 3 layers? It isn't.

While we're at it, what is line 1? Or 2?

The opacities should not be linear. You should get 100 50 33 25 20 17.
20%
25%, 20%
33.3%, 26.66%, 20%
50%, 40%, 30%, 20%
100%, 80%, 60%, 40%, 20%

100% is on bottom and 20% on top. Since 20% is the top opacity it leaves 80% of all of the layers below it. So .8 times 100% brings it down to 80%, 50% down to 40%, etc. And then I apply layer 2 to 3, 4, and 5 by multiplying by .75 and continue on until everything is brought down to 20% each.
 
  • #35
LightningInAJar said:
20%
25%, 20%
33.3%, 26.66%, 20%
50%, 40%, 30%, 20%
100%, 80%, 60%, 40%, 20%

100% is on bottom and 20% on top. Since 20% is the top opacity it leaves 80% of all of the layers below it. So .8 times 100% brings it down to 80%, 50% down to 40%, etc. And then I apply layer 2 to 3, 4, and 5 by multiplying by .75 and continue on until everything is brought down to 20% each.
But why?? Its mystifying what you are trying to do.

What is it about the last 2 dozen posts of tutelage that makes you not want to do it this way?
 
  • Like
Likes hutchphd
  • #36
DaveC426913 said:
But why?? Its mystifying what you are trying to do.

What is it about the last 2 dozen posts of tutelage that makes you not want to do it this way?
What do you mean? Doesn't this method show that each photo is equally represented? That is what I wanted to do rather than take anyone's word for it.
 
  • #37
LightningInAJar said:
What do you mean? Doesn't this method show that each photo is equally represented? That is what I wanted to do rather than take anyone's word for it.
I had hoped I'd done that in post 22.

Still, I'm not convinced your math is sound, even if you appear to arrive at a satisfactory answer. You start off multiplying by .8 and then later on you switch to multiplying by .75. (I guess you implicitly follow up with multiplying by .667 and then by .5 , but how do you know/prove those are the right numbers?)
 
  • #38
DaveC426913 said:
I had hoped I'd done that in post 22.

Still, I'm not convinced your math is sound, even if you appear to arrive at a satisfactory answer. You start off multiplying by .8 and then later on you switch to multiplying by .75. (I guess you implicitly follow up with multiplying by .667 and then by .5 , but how do you know/prove those are the right numbers?)
Your post at 22 appeared to be mostly visual which relies on healthy retinas which I don't have. I assume my process works because I ended with all layers having 20% left. Would different numbers result in the same outcome?
 
  • #39
LightningInAJar said:
Your post at 22 appeared to be mostly visual which relies on healthy retinas which I don't have. I assume my process works because I ended with all layers having 20% left. Would different numbers result in the same outcome?
It doesn't really work because, in general, you don't have those percentages available for you. What do you do for 6 layers instead of 5? Or 130 layers for those astrophotographers like me who stack lots of images together?

A better method is the one shown in post #25, where each layer has an opacity equal to 1/n, where n is the layer number.
Take a look at post #33 again where I went through n=2 and n=3.
 
  • #40
LightningInAJar said:
Your post at 22 appeared to be mostly visual which relies on healthy retinas which I don't have. I assume my process works because I ended with all layers having 20% left. Would different numbers result in the same outcome?
But there is no mystery in those numbers. The opacity of each layer ##L_n## is ##\frac{1}{n}## in a percentage form.
Question: Why does that work?
Answer: It works because the n'th layer gets 1/n opacity and leaves (n-1)/n opacity for all the lower layers. That (n-1) multiplier cancels the 1/(n-1) opacity for the (n-1) layer.
##\frac{1}{n} L_n + \frac{n-1}{n} ( \frac{1}{n-1} L_{n-1} + \frac{n-2}{n-1} (\frac{1}{n-2} ... ##
is the same as
##\frac{1}{n} L_n + \frac{1}{n} ( L_{n-1} + (n-2) ( \frac{1}{n-2} ... ##
So the (n-1) factors are gone. Likewise, the (n-2) factors all cancel and are gone. Likewise (n-3). etc. etc. etc.
After all the canceling is done, only the ##\frac{1}{n}## of the top layer remains to multiply all the layers equally.
 
Last edited:
  • Like
Likes Drakkith
  • #41
Drakkith said:
It doesn't really work because, in general, you don't have those percentages available for you. What do you do for 6 layers instead of 5? Or 130 layers for those astrophotographers like me who stack lots of images together?

A better method is the one shown in post #25, where each layer has an opacity equal to 1/n, where n is the layer number.
Take a look at post #33 again where I went through n=2 and n=3.
If I had 6 layers instead of 5 I would simply multiply everything by .83 on top of everything before that. That is 5/6ths.
 
  • #42
LightningInAJar said:
If I had 6 layers instead of 5 I would simply multiply everything by .83 on top of everything before that. That is 5/6ths.
Your method requires several more steps than the method we outlined, but different strokes for different folks.
 
  • #43
LightningInAJar said:
If I had 6 layers instead of 5 I would simply multiply everything by .83 on top of everything before that. That is 5/6ths.
IMO, the only reason to do this is to convince yourself that the final result gives equal opacity to all the layers. Your approach only does that for one example at a time and it seems like a coincidence each time. You can add a 6'th layer and show that it works for 6 layers, but does that make you confident about WHY it works enough to say that it would also work for 15 layers? Or 115 layers? I think that the only insight you get from your approach is that it worked "by magic".
There are better ways to approach it that are much more convincing that it always works for any number of layers (for instance posts #31 and #40). That is what we keep trying to convince you of.
 
Last edited:
  • #44
I have trouble understanding your methods. I am not good at reading math notations. And convincing myself that it does equal for all images is what I care about. If I needed to stack much more than 20 images I would probably use an auto tool anyway. The manual method doesn't work with anything less than whole number percentages so I likely could only screw it up with those higher numbers. Any simple formula that is less multi-step that represents the concept?
 
  • #45
Sure. Add each pixel value together and then divide by the number of photos. In other words, add every (1,1) pixel from each image together and divide by the number of images. Then do the same for all (1,2) pixels, all (1,3) pixels, etc.
 
  • #46
Following @hutchphd's post #25 which recommends using induction:
We know that for one level, it is trivially true. 1/1 (=100%) is the right opacity for one level. For opacities, we will use fractions instead of percentages (e.g. 100%=1, 50%=1/2, 33%=1/3, 25%=1/4, 20%=1/5, etc.)

Suppose that for n levels, we have that our method gives opacities of 1/n equally for each level. Call it the ##mergedNLowerLevels = 1/nL_n+1/nL_{n-1}+...+1/nL_1 = 1/n(L_n+L_{n-1}+...+L_1)##.
(Example of 5 levels: ##1/5L_5 + 1/5L_4 + 1/5L_3 +1/5L_2 + 1/5L_1 = 1/5(L_5+L_4+L_3+L_2+L_1)## call this the ##merged5LowerLevels##)
Now let's add one more level, ##L_{n+1}##
(Example add level ##L_6##).
Our method is to give an opacity of 1/(n+1) to the new level, ##L_{n+1}##, and n/(n+1) to the ##mergedNLowerLevels##
##1/(n+1)L_{n+1} + n/(n+1) (mergedNLowerLevels)##
(Example: ##1/6L_6 + 5/6 (merged5LowerLevels)##).
Because we supposed that the method worked for that merging of n lower levels, we have
##mergedNLowerLevels = 1/n(L_n + L_{n-1} + ... + L_1)##
(Example: ##merged5LowerLevels=1/5(L_5 + L_4 + L_3 +L_2 + L_1)## )
So with the new level we have ##1/(n+1)L_{n+1} + n/(n+1)(1/n(L_n + L_{n-1} + ... + L_1))##
(Example ##1/6L_6 + 5/6(1/5(L_5+L_4+L_3+L_2+L_1)## )
Canceling the ##n## multiplier with the ##1/n## gives ##1/(n+1)(L_{n+1}+L_n+L_{n-1}+...+L_1)##
(Example: Canceling the 5's in ##5/6(1/5 ...)## gives ##1/6(L_6+L_5+...+L_1)##
So our method gives equal opacities with the added level.
With this, we know that our method works for 1, 2, ..., n and n+1 and then n+2 and then n+3, ... all the way up to any number of layers.
 
Last edited:
  • Like
Likes hutchphd
  • #47
LightningInAJar said:
Any simple formula that is less multi-step that represents the concept?
Again, yes.

On = 100/n
Where
O = opacity (as a %)
n = layer number (bottom layer being 1)
 
  • Like
Likes hutchphd

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
7K
Replies
2
Views
2K
Replies
21
Views
2K
  • · Replies 35 ·
2
Replies
35
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K