Open Photography Forums  

Go Back   Open Photography Forums > Digital Darkroom > Image Processing and Workflow

Image Processing and Workflow RAW, DNG , TIFF and JPG. From Capture to Ready for Publish/Display. All software and techniques used within an image workflow, (except extensive retouching and repair or DAM).

Thread Tools Display Modes
Old May 27th, 2011, 09:03 PM
Doug Kerr Doug Kerr is online now
Senior Member
Join Date: May 2006
Location: Alamogordo, New Mexico, USA
Posts: 8,602
Default Photoshop - "Reading" the color and transparency of a region


In a Photoshop image layer, each pixel has both a color and an opacity. In the common situation, every pixel has opacity 100%, and if this is the only layer - or if in fact it is the topmost of several layers and the blend mode is Normal - we will "see" just the color of each pixel. It we examine the image with the Info panel, we will "read" the color of each pixel. But in other situations, we do not "see", nor do we "read", the color and opacity of the pixels on the layer. Here I discuss how we can determine those values.
Before I get started. note that in the examples to follow, I assume that Photoshop is using its default for calculation of color blends - that is, the math works on the actual R, G, and B values - not the "blend at gamma 1.00" mode, in which the calculations work on the luminance implied by the R, G, and B values.
Color and opacity

In a Photoshop image layer, each pixel has both a color and an opacity. In the common situation, every pixel has opacity 100%, but we can set it to another value in various ways

directly, when we set the color/opacity to which an area is to be "filled"
globally, by setting the layer opacity to some value less than 100%.
with a semitransparent area of a mask

If we do two or more, the effective opacity of each pixel is the product of (the actual multiplication is done using a scale of 0-1 rather than 0-100%):

its "individual" opacity (100% by default)

the layer opacity (100% by default)

100-the mask opacity (100% if the mask is fully transparent at the point of interest, or if there is no mask)

The impact of opacity

The impact of the opacity is most often noted when there is a layer below the layer of interest.
Let me right now assume that the pixels of this lower layer all have the default value of 100%.
Now, consider a pixel on our (upper) layer with a certain color and opacity 60%. That means that when we look at that pixel, we "40% see right through it". That means that the color we see is the composite (in terms of R, G, and B values) of only 60% of the color of the pixel itself (the part "we don't miss" by looking though it) plus 40% of the values of the pixel below it.

If we examine the composite image with the Info panel, we will see these composite color values.

Getting the scoop

But suppose that for our top layer, we want to know the actual coded color values, and maybe as well the opacity, in some particular region. To understand one way to get that, let's first consider a couple of special situations.

In one case, the layer below is all black (and with opacity 100%). Then, for any given color "channel", the value shown on the Info panel will be 60% of the pixel's assigned color value plus 40% of 0 (the value for the black layer below).

In the second case, the layer below is all white (and with opacity 100%. Then, for any given color "channel", the value shown on the Info panel will be 60% of the pixel's assigned color value plus 40% of 255 (the value for the white layer below).

Now, if we have the data for those two cases, we can by some simple algebra determine the actual pixel color coordinates and the opacity. [I won't go through that here, however.]

But that's a bit of a pain, what with having to make two special background layers and such.

A simpler way

There is a simpler way.

Let's consider our top layer again. If there is no layer below (or if there one is but we "switch it off"), we see visually a combination of 60% of the pixel color values plus 40% of the color values of the local color of the gray checkerboard pattern that (by default) indicates "the great empty beyond".

But if we examine the layer with the Info panel, we will see the actual "coded" color of the pixels. The program does not discount it to 60% of its coded values, nor add in 40% of some indeterminate lower color.

Now if we in fact want to know the opacity as well, I'm afraid we will need to put in a temporary background layer, just below the layer of interest. It's easiest to make it black (0,0,0).

I'll explain the calculation with an example. Let's assume that for some pixel of interest, one of the color values is 200, and the opacity is 60%

With a black layer below, the value of the color coordinate that will be read by the Info panel) is 60% of 200 (120) plus 40% of 0 (0) - that is, 120.

But with the black layer (and any other real layer below turned off), we will see 200 - period.

So we determine what percentage of 200 is 120:


The answer is of course 60% - which we know is the opacity of the pixel of interest.

An example calculation

Now lets do an entire example.

With a black layer below the layer of interest, we read:

RGB = 140, 105, 63

With the black layer (and any other layers below) turned off, we read:

RGB = 200, 150, 90

Thus we know that the coded color of the pixels is 200, 150, 90.

Now, we take any color channel we wish - let's use R. We make this calculation, based on the R value reported in the two cases:

(140/200)*100% = 70%

Thus we know that the opacity of the pixels is 70%.

More complicated situations

Suppose we have two layers in an image buildup that both have transparency. We may wish to treat that pair as a "subassembly" in a more complicated image buildup.

The two of them together act like a single layer having, at each pixel, a certain coded color and a certain opacity. We may wish to describe them as the effective coded color and the effective opacity of the pair of layers at that pixel.

We can determine those values using just the technique described above. With all layers below disabled, we read the R, G, and B values at the pixel of interest. This is the effective color of the two layers together.

Then, with a black layer temporarily inserted just below the pair, we read any one of the values again. From that, and the corresponding value with all lower layers turned off, we can determine the effective opacity of the layer pair.

Best regards,

Reply With Quote


Thread Tools
Display Modes

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

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 11:20 AM.

Posting images or text grants license to OPF, yet of such remain with its creator. Still, all assembled discussion 2006-2017 Asher Kelman (all rights reserved) Posts with new theme or unusual image might be moved/copied to a new thread!