# Can someone explain the exact behavior of add/subtract/intersect/invert for alpha channels in photoshop?

Suppose I have two different single pixel (ie 1x1 pixel) alpha channels.

The channels are called A and B.

Since everything is grayscale, I will normalize my alpha channel values to between 0 and 1, 0 being completely black and 1 being completely white.

I would like a formula that tells me the result when I subtract B from A (On a mac, this is Cmd+Click A and then Option+Cmd+Click B and then create a new alpha channel and paint bucket in 100% white). Let the result be denoted A - B.

Similarly, I would also like a formula that tells me the result when I add B to A (using shift+cmd+click on a mac). Let this be denoted A+B.

I would also like a formula that tells me the result when I intersect A and B (shift+option+cmd+click on a mac). Let this be denoted A cap B.

I would also like a formula that tells me the result when I invert A (Cmd+I on a mac). Let this be denoted Inv(A).

I'm using the latest version of photoshop.

Here are some examples to show that this is not what one might think:

Suppose A = 1 and B = 0.5. Then A - B = 0.66666 = 2/3. Why???

Suppose A = 0.5, then Inv(A) = 0.66666 = 2/3. Why?????

Suppose A = 0.25, then Inv(A) = 0.86. Why????

Suppose A = 0.5, then A cap A = 0.24. Why?????

Suppose A = 0.5, then (A cap A) cap A = 0.1 Whyyyyyyy?

Is there a reference where this is all explained?

• What are the results you're referring to? New channel, layer from selection, quick mask...? When I subtract 1 - 0.5 I'm getting 0.5, Inverted 0.5 gives me 0.5, etc: so everything works as expected. Could you upload screenshots of the results, psds? – Sergey Kritskiy Aug 25 '19 at 8:12
• @SergeyKritskiy The simplest example is this. I create a new alpha channel, fill it with a value of 0.5 (50% gray). Then I hit "Cmd+I" (to invert), and the result is 0.66. You can find the psd document here: drive.google.com/file/d/1mw5_Jz8XdiLaDRt8SOa8D_Dcp_gNOgOm/… – Will Chen Aug 25 '19 at 8:37
• Color is not linear, whether alpha should be is a bit debatable... – joojaa Aug 25 '19 at 11:08

## 1 Answer

This is probably because you have `Dot 20%` (or something similar) as `Gray Working Space` in `Edit > Color Settings` menu — this profile is intended for printing greyscale images and it's not the same as digital gamma corrected greyscale gauge.

Someone with better knowledge of how color profiles work might explain what exactly happens in there but `#808080` in `Dot 20%` equals to `#696969` in gamma corrected working space. Here's a comparison: on the left your file with `#808080` B and `A-B` being `#a9a9a9` in `Dot 20%` grey working space and on the right your file with `2.2 Gamma` working space: A-B is as being expected, `#808080`:

I dont know if that's a bug or a feature, that by default PS has a confusing gamma correction for channels (looks like a bug to me?) but changing Grey to Generic 2.2 gamma profile should fix the calculations.

• Well it is perfectly reasonable that alpha is affected by gamma correction for most operations. But for many not so much. – joojaa Aug 25 '19 at 11:07
• Okay so I'm doing this experiment again, with a new fresh photoshop canvas, and now inverting a 50% gray thing gives me a 52% gray thing (This is when color settings is "north america general purpose 2". If I then change the gray working space to "generic gray gamma profile 2.2" then inverting 50% gray gives me 35% gray...so I'm still confused – Will Chen Aug 29 '19 at 3:00
• When you switched the profile, did you fill your channel with 50% grey again? Otherwise the grey you had from a previous profile is a gamma corrected one (= not 50%) – Sergey Kritskiy Aug 29 '19 at 6:15