• Please use real names.

    Greetings to all who have registered to OPF and those guests taking a look around. Please use real names. Registrations with fictitious names will not be processed. REAL NAMES ONLY will be processed

    Firstname Lastname

    Register

    We are a courteous and supportive community. No need to hide behind an alia. If you have a genuine need for privacy/secrecy then let me know!
  • Welcome to the new site. Here's a thread about the update where you can post your feedback, ask questions or spot those nasty bugs!

Photoshop - drawing pixel masks

Doug Kerr

Well-known member
As many of you know, I do not regularly use Photoshop, and am not very fluent with even its basic tools. Thus I am perhaps eminently unqualified to offer hints on its use.

Still, when I decide I need to know how to do something, I may look at it with a fresh approach, perhaps informed by an exhaustive study of one tiny part of the application's nature. And perhaps that outlook will be helpful to other, more experienced, workers.

I began doing some work that required me to generate pixel masks to isolate certain objects from the overall content of a certain layer. I was at first frustrated by the context - mainly just how do I see what I am doing.

The answer was by way of the proper exploitation of basic Photoshop capabilities.

I thought I would review my conclusions here. Some, even experienced with the application, may not have realized how these simple tools can facilitate the operation I describe. And of course there may well be those here who can tell me of an even easier way to do it.

I won't describe the procedure as such. Rather, I will describe the state in which I work.

I work with the system in this state; the layer on which I work will be called here the "working layer":

• Working layer visible
• All other content layers invisible
• Pixel (“layer”) mask on the working layer, initially all-opaque.
• Pixel mask disabled (allows us to see the entire image on the working layer).
• Red overlay in effect for the pixel mask (allows us to see where we have “opened” the mask). (It may be helpful to use a mask opacity less than the default 50%.)

Then, with the pixel mask selected, I draw transparent areas with a brush with white, and then where needed restore areas to the opaque state by drawing with black. (I was never good at painting within the lines!) The transparent area (showing the part of the content that is to be "retained") will lose its red overlay.

When we are done, the pixel mask should be re-enabled (to ensure that only the chosen parts of the content of the layer will appear in the overall image buildup).

There are of course numerous keyboard shortcuts to facilitate this, including:

• Establish a pixel mask on the working layer, initially all-opaque: with the working layer selected, Alt-click on the "Add a pixel mask" icon on the Masks panel.
• Disable the pixel mask on the working layer: with the working layer selected, Shift-click on the pixel mask thumbnail.
• Enable the red overlay (showing the opaque regions of the mask): with the working layer selected, Alt-Shift-click on the pixel mask thumbnail.
• Shift between white and black "ink" in the drawing brush: key X. (If somehow some other color got into that palette, key D to nominate black and white; black will then be "up"; key D if you need white.)

Well, that's it. No big news I'm sure.

Best regards,

Doug
 

Doug Kerr

Well-known member
Here is a related tip, also certainly known to skilled Photoshop operators.

When needing a pixel mask on a layer, we may wish to benefit from some of the tools that can be used to make a Selection (as for example the Quick Selection tool or the Magic Wand tool).

We may use these tools to identify as the Selection the wanted region on the layer of interest (before we have established a pixel mask there).

Then, if we establish the pixel mask (the normal way up, with a click on the Add Pixel Mask icon on the Masks panel), the pixel mask that is initially established will reflect the Selection. (The Selection as such will vanish.) The selected area will be transparent in the mask, and the remainder opaque.

We can easily see this by doing Alt-Shift-click on the pixel mask thumbnail to activate the red overlay.

Best regards,

Doug
 

Asher Kelman

OPF Owner/Editor-in-Chief
Then, with the pixel mask selected, I draw transparent areas with a brush with white, and then where needed restore areas to the opaque state by drawing with black. (I was never good at painting within the lines!) The transparent area (showing the part of the content that is to be "retained") will lose its red overlay.

Dd you alter the presets, or am I missing something? Normally white hides the layer below and black reveals it. Maybe sharing the file might allow us to see your setup.

Asher
 

Doug Kerr

Well-known member
Hi, Asher,

Dd you alter the presets, or am I missing something? Normally white hides the layer below and black reveals it.
There are two separate issues here: the effect of a mask on the content on its own layer, and the effect of that on layers below.

Assume that the mask in question is on a layer with "content". A mask on such a layer only (directly) affects content on that layer. By doing so, it may have an indirect effect on the visibility of pixels on a lower layer. And that effect will seem "reversed".

With respect to the layer with the mask, a transparent area (painted with white) "makes live" the image pixels there; an opaque area (painted with black) makes the pixels there "ineffectual" (by making them transparent).

Thus, if only the layer on which we are working is visible, we will see the parts of the content on that layer that are in the "transparent ("white") region of the mask, and we will not see the parts of the content that are in the opaque ("black" region).

Now, if we make visible a lower layer (also with content), then:

• Where the pixels on the upper layer are "active", as a result of the mask there being transparent, or "white", we do not see the pixels on the lower layer; that is because they are masked by the active pixels on the upper layer (not by the mask on the upper layer itself).

• Where the pixels on the upper layer are "dead" (that is to say, transparent), as a result of the mask at those points being opaque (black), then we do see the pixels on the lower layer. Again, they are made visible not by the mask on the layer above itself, but rather because the mask on the upper layer makes "dead" the pixels of the layer content in such a region, so they cannot mask viability of the pixels in that region on the lower layer.

Again the important point is that a mask on one content layer does not directly affect the visibility of content on a lower layer; it affects the capability of the content on its own layer to block visibility of pixels on a lower layer.

I will make a demo file after lunch. How is the best way to "send" it?

Best regards,

Doug
 

Asher Kelman

OPF Owner/Editor-in-Chief
Great! We're talking about the same thing but you are referencing the layer for which there's a mask.

In practice, we are generally altering the layer below. Masking with curves or other filters reference the effect on the layer below and whether or not we see the unaltered mage: white conceals the unaltered image, (revealing the effect of the new layer on the layer below) and black likewise allows us to see the layer below, (unaltered). In short we generally talk of the mask as "black reveals", "white conceals" as we reference the layer below the mask. That seems to be the convention as far as I know!

Asher
 

Doug Kerr

Well-known member
Hi, Asher,

It seems as if we are already together.

I have no comment on what "we generally speak of".

I prefer to think in terms of:
• What drawing on the mask with black or white does to the mask.
• The mask being transparent or opaque.
• The effect that may have on that layer.
• The effect that may have on a layer below.

And I try to make it clear what layer I am referring to.

And various of these are important to me as I work.

In any case, just to help illustrate this, here are some looks at a test file:

This is the content of the lower layer:

Mask_test_01-01R.jpg

This is the content of the upper layer:

Mask_test_01-02R.jpg

Here is the pixel mask on the upper layer as we see it in B/W:

Mask_test_01-04R.jpg

[continued]
 

Doug Kerr

Well-known member
[continued]

Here is what we would see with the mask enabled and the lower layer invisible:

Mask_test_01-03R.jpg

We see the "enabled" (that is, not "dead", or looking at it another way, the "not made transparent") material from the upper layer content.

Here is the composite image:

Mask_test_01-05R.jpg

So yes, where we painted on the mask with white, the original content of the lower layer is blocked (overlaid by the "enabled" content of the upper layer - note that the layer blend mode here is "normal").

Note however that if we use a different layer blend mode (here, "lighten"), then white on the mask on the upper layer does not result in the content of the lower layer being blocked:

Mask_test_01-06R.jpg

Thus, it is not attractive to look at the mask on the upper layer as (itself) affecting the visibility of pixels on the lower layer.

Best regards,

Doug
 

Asher Kelman

OPF Owner/Editor-in-Chief
Doug,

As long as you use references that work for you, this is productive. Still, the convention refers to the underlying layer.

Now how are you going to clean up the chain before the lady gets it in her hand; I mean getting rid of the unwanted blue pixels?

This case is one of apparently needing to extract the chain from it's original layer. The most efficient way is to use the specific tools Photoshop has for that. Masking with a brush is too clumsy.

Asher
 
Doug, You're a pitiful masker :)

Shall I take some time to make a small discourse on how to alter masks (from my little knowledge) with some barely used tools (and some filters) in your own thread?

As you said, probably already known by many of the users...

If yes, I'll do that later tomorrow (my tomorrow)....
 

Doug Kerr

Well-known member
Hi, Asher,

Doug,

As long as you use references that work for you, this is productive. Still, the convention refers to the underlying layer.
I see.

Somebody needs to tell Adobe; from the Photoshop Help facility:

A layer mask [they half the time call pixel masks that] is a grayscale image, so areas you paint in black are hidden, areas you paint in white are visible . . .​

Now, how is it that we describe the two states of the mask? (examples: yes/no, pass/block, transparent/opaque).

Now how are you going to clean up the chain before the lady gets it in her hand; I mean getting rid of the unwanted blue pixels?
Not needed for this purpose, which was to illustrate how the mask works!

This case is one of apparently needing to extract the chain from it's original layer. The most efficient way is to use the specific tools Photoshop has for that. Masking with a brush is too clumsy.
Of course. I'm still learning how to use those tools.

If I were actually trying to isolate the pulling blocks here, which of those would be the best?

Best regards,

Doug
 
Photoshop CS5 has some particularly good selection tools. In most cases, you'd use the quick selection tool for the initial selection and hone in on the selection after clicking the [Refine Edge button] that would appear at the top of the screen. However in this case it may not work so well.

I think the easiest way is to use Select/ Color Range ... and click on the sky. That will give you a mask where you can easily isolate the blocks. However, you'll still have the cables, which you will want to eliminate. I'd suggest first painting on the mask to eliminate them from the sky around the blocks. You'd also want to carefully use a brush so her fingers can wrap over the cable for the blocks. You need to use an appropriate amount of hardness or softness when you use the brush.

However, that still leaves bits of the cables over the blocks. I'd suggest next selecting the two layers and using [Ctrl][Shift][Alt] to create a new composite layer above them. Then, if you have CS5, you could use the spot healing brush, which has content aware fill capabilities, to clean up the blocks. If you have an earlier version, you'll probably have to painstakingly clone at high magnification.
 

Doug Kerr

Well-known member
Hi, Murray,

Photoshop CS5 has some particularly good selection tools. In most cases, you'd use the quick selection tool for the initial selection and hone in on the selection after clicking the [Refine Edge button] that would appear at the top of the screen. However in this case it may not work so well.

I think the easiest way is to use Select/ Color Range ... and click on the sky. That will give you a mask where you can easily isolate the blocks. However, you'll still have the cables, which you will want to eliminate. I'd suggest first painting on the mask to eliminate them from the sky around the blocks. You'd also want to carefully use a brush so her fingers can wrap over the cable for the blocks. You need to use an appropriate amount of hardness or softness when you use the brush.

However, that still leaves bits of the cables over the blocks. I'd suggest next selecting the two layers and using [Ctrl][Shift][Alt] to create a new composite layer above them. Then, if you have CS5, you could use the spot healing brush, which has content aware fill capabilities, to clean up the blocks. If you have an earlier version, you'll probably have to painstakingly clone at high magnification.

Thanks for that insight.

Note that of course this is not actually a task I am trying to do!

Best regards,

Doug
 

Doug Kerr

Well-known member
Hi, Murray,

I think maybe it is Ctrl-Alt-E, or Ctrl-Shift-Alt-E to merge all visible layers without needing to select them.

Best regards,

Doug
 
Hi, Asher,


I see.

Somebody needs to tell Adobe; from the Photoshop Help facility:

A layer mask [they half the time call pixel masks that] is a grayscale image, so areas you paint in black are hidden, areas you paint in white are visible . . .​

Now, how is it that we describe the two states of the mask? (examples: yes/no, pass/block, transparent/opaque).

Hi Doug,

I visualize what I need to do by viewing the mask as a multiplier between 0 and 1, or 0% and 100%, (divide the 0 - 255 pixel values by 255), which it of course is in reality. If I paint the mask with black (0) then the layer where I'm painting the mask will be hidden (0% opaque 100% transparent), if I paint the mask with white then the layer will be visible (100% opaque and 0% transparent). One can also paint with gray for semi opaque. We are adding opacity when we make a mask, just like in the old days when we literally added a filter layer on the film, which blocked the light for which the film was sensitive.

If I were actually trying to isolate the pulling blocks here, which of those would be the best?

With difficult shapes it often helps to zoom in a lot, and use a lasso tool to trace the edge of the object/subject and make a selection. That allows to add a bit of feathering to the selection before turning the selection into a mask. One can also us some blur on the mask, or local sharpening, to alter the edge transition. Recent Photoshop versions have useful edge refinement options to tweak the edges of a selection.

When a subject (or its background) has a prominent color, you can also inspect the color channels to see if they already offer a nice black and white start, copy the channel and paste into the mask and paint the irrelevant parts of the mask with black. For that purpose one can also use a duplicate of the image and convert it to CMYK, or use a channel mixer version of the image. We can use whatever creates a nice contrast with the immediate background as a basis for our mask. Also the Select by Color menu item can help, although one needs to be careful with specular reflectons on our subject which may have a different color.

Always useful is the notion that one can invert a selection or a mask, so selecting the surroundings instead of the subject itself can sometimes be more efficient as a start. Selections can also be saved, and the resulting alpha channel can be (re-)used to make a mask, either by copying or by filling the earlier selection on the mask with white or black.

Photoshop offers an incredible number of possibilities to create selections and make masks. The difficulty is in selecting the method(s) that achieves our goal the fastest for the specific task at hand.

Cheers,
Bart
 
Since CS4 (maybe earlier?) in the "mask" panel, you have a "density" slider that operate like an opacity slider on layers but only on the mask. When painting, it's extremely useful to lower the density in order to see what's underneath (in that case, the lady) and be able to still see the masking area. You could turn the opacity slider as well but in that case "everything" vanishes, not only the mask.
 

Doug Kerr

Well-known member
Hi, Sandrine,

Since CS4 (maybe earlier?) in the "mask" panel, you have a "density" slider that operate like an opacity slider on layers but only on the mask. When painting, it's extremely useful to lower the density in order to see what's underneath (in that case, the lady) and be able to still see the masking area. You could turn the opacity slider as well but in that case "everything" vanishes, not only the mask.
Indeed.

A considertion with that is that when we decrease the density of the mask, its actual effect is "diluted" - not just its effect as we see it.

Thus, when we are done with making the mask, we must restore the density to 100% to have the mask actually do what we expect (assuming we in fact want it to be all either wholly opaque or wholly transparent). But that's not a big deal.

Thanks for the suggestion.

Best regards,

Doug
 

Doug Kerr

Well-known member
Hi, Bart,
Hi Doug,

I visualize what I need to do by viewing the mask as a multiplier between 0 and 1, or 0% and 100%, (divide the 0 - 255 pixel values by 255), which it of course is in reality. If I paint the mask with black (0) then the layer where I'm painting the mask will be hidden (0% opaque 100% transparent), if I paint the mask with white then the layer will be visible (100% opaque and 0% transparent).
In fact, where we paint with white, the mask becomes fully transparent. Where we paint with black, the mask becomes fully opaque. But we have to be careful where we reckon its effect to see that properly.

We can see that most clearly with these three models.

Model 1

We have only one layer, which has an image. On that layer, we create a pixel mask.

Where the mask is transparent (that is, where we have painted the mask with white), the pixels of the image are seen.

Where the mask is opaque (that is, where we have painted the mask with black), the pixels of the image are not seen. (They have actually been made, as pixels, transparent, which makes them invisible.)

Nothing in this story makes it seem as if the mask, where "white", blocks image pixels.

Model 2

We have a layer containing an image. Above it, we create an adjustment layer, say to control saturation. We set it to reduce the saturation all the way.

There is a mask on that layer. We paint some "on the mask".

First I will describe the result, in neutral language.

• Where the mask is "white", the composite image has no saturation.

• Where the mask is "black", the composite image has its original saturation.

This can be explained in two ways:

a. Where the mask is "white", it is "transparent", meaning that it "lets through" the effect of the adjustment. Thus, only where it is transparent ("white") does the adjustment have any effect on the image (in this case, reducing its saturation).

b. The adjustment layer has, in effect, a copy of the image on the layer(s) below, modified (all over) by the adjustment setting. (In this case, that would be an entire image with reduced saturation.) We cannot view this auxiliary image.

Where the mask is transparent ("white"), the pixels of this second image are "let through" (and are "live"). Assuming that the blend mode is normal, we will then see those pixels rather than the pixels of the main image (underneath). Thus in such regions we will see reduced saturation.

Where the mask is opaque ("black"), the pixels of this second image are "not let through". Technically, those pixels are made transparent. Thus, we see right through them and see the pixels of the original image underneath we will then see those pixels rather than the pixels of the main image (underneath). Thus in such regions we will see the original saturation.

Model 3

We have two layers, each containing images. On the upper layer, there is a mask. Part of it is "black" and part "white"

Where the mask is "white", the pixels of the upper layer image are "let through". Technically, they are allowed to retain their original opaque state (as pixels).

In those regions, we see the upper-layer pixels in the composite image. Since those pixels are opaque, they block the view of the lower-layer pixels below. From the standpoint of the result, they are included in the composite image.

Where the mask is "black", the pixels of the upper layer image are "killed". Technically, they are made transparent (as pixels).

In those regions, we do not see the upper-layer pixels in the composite image. Since those pixels are transparent, we see right through them to the lower-layer pixels below. From the standpoint of the result, they are excluded from the composite image.

Now here, some say that, since in the "white region" of the mask, we cannot see the lower layer pixels (they are "covered-up" by the upper layer pixels in that region), the mask has "blocked" the lower-layer pixels.

I do not find that characterization attractive, or even correct.

==========

Thus, in every case, we see that where the mask is "white" (transparent), it "allows" participation by the essence of its layer (which is what it governs). Where the mask is "black" (opaque), it "prevents" participation by the essence of its layer.

Part of the language problem here is that where a mask is opaque ("black"), it renders the pixels there invisible, but the way it does that is to make them transparent (as pixels). Thus we can readily get confused as to the meaning of "transparency" of a mask.

To summarize,

• where the mask on a layer is opaque ("black"), it makes the pixels on that layer transparent (as pixels). Thus they will be invisible, and anything below will be seen.

• where the mask on a layer is transparent ("white"), it leaves the pixels on that layer alone, and thus in their usual state, which is opaque (as pixels). Thus they will be visible, and anything below will not be seen.


If we speak of a mask where it is "white" as "opaque" or "blocking image pixels", we jump one step in the chain of cause and effect. That can be harmless so long as we realize what we are doing.

=========

With difficult shapes it often helps to zoom in a lot, and use a lasso tool to trace the edge of the object/subject and make a selection. That allows to add a bit of feathering to the selection before turning the selection into a mask. One can also us some blur on the mask, or local sharpening, to alter the edge transition. Recent Photoshop versions have useful edge refinement options to tweak the edges of a selection.
Yes, and I have only just begun to explore the use of all those.

When a subject (or its background) has a prominent color, you can also inspect the color channels to see if they already offer a nice black and white start, copy the channel and paste into the mask and paint the irrelevant parts of the mask with black. For that purpose one can also use a duplicate of the image and convert it to CMYK, or use a channel mixer version of the image. We can use whatever creates a nice contrast with the immediate background as a basis for our mask. Also the Select by Color menu item can help, although one needs to be careful with specular reflectons on our subject which may have a different color.
Yes, I can see that could be very useful.

Always useful is the notion that one can invert a selection or a mask, so selecting the surroundings instead of the subject itself can sometimes be more efficient as a start. Selections can also be saved, and the resulting alpha channel can be (re-)used to make a mask, either by copying or by filling the earlier selection on the mask with white or black.
Yes, indeed.

Photoshop offers an incredible number of possibilities to create selections and make masks. The difficulty is in selecting the method(s) that achieves our goal the fastest for the specific task at hand.

Indeed.

Thansk so much for your help.

Best regards,

Doug
 

Doug Kerr

Well-known member
The best way to understand what a layer mask really does is to look at it doing that, where it does it.

I think this presentation does that.

The scenario is a file with one layer, carrying an image. We will put a pixel mask on that layer.

Here we see the layer image with no mask in effect:

Mask_test_05-01R.jpg

We then create on that layer a pixel mask. In "black/white" form (as we might paint on it) it looks like this:

Mask_test_05-02R.jpg

With the mask active, the image looks like this on the screen:

Mask_test_05-03R.jpg

The checkerboard pattern tells us that in that area, the pixels are transparent (that's why they are "invisible") and that there is nothing below to be seen through them. (The checkerboard is thus the visible representation of "the great emptiness below" into which we gaze through these transparent pixels.)

If we save this image as a JPEG file, it will look like this:

Mask_test_05-04R.jpg

Whence the white? Photoshop, when saving to JPEG an image in which some pixels are transparent (at every layer), renders those as white (in effect putting a white sheet at the rear of the stack, in front of the "the great emptiness below").

I have added a border for clarity.​

Now what does this show us?

It shows us that:

• Where the mask is "white", which we describe in formal mask language as transparent, it allows the pixels on its layer (which is what it governs) to be seen, to participate in the overall image.

• Where the mask is "black", which we describe in formal mask language as opaque, it does not allow the pixels in its layer to be seen, to participate in the overall image.
Now there can be many ramifications of this "downline", especially when there are multiple layers involved. These are all of importance to us.

But in fact what the mask does, at the place where it actually works, is as described above.

Best regards,

Doug
 

Doug Kerr

Well-known member
Now I will add to the presentation to take into account mask semitransparency (caused by painting on the mask with gray). Recall that the exercise here is to watch the mask at work, where it works, noting its effect on what it works on (pixels of its layer)

Again the he scenario is a file with one layer, carrying an image. We will put a pixel mask on that layer.

Here we see the layer image with no mask in effect:

Mask_test_06-01R.jpg

We then create on that layer a pixel mask. In "black/white" form (as we might paint on it) it looks like this:

Mask_test_06-02R.jpg

It has a rectangular "white" region, which is transparent, a circular "gray" region, which is 40% transparent, and the remainder is "black" (opaque).

The gray region was painted with RGB=123,123,123. In Photoshop, the transparency coefficient, t, of a mask region painted with RGB=CCC is given by:
t=(C/256)^1.25

The effect of a mask region with transparency coefficient t is that the pixels there, whose native opacity ("potency") is 100%, will only participate in the overall image buildup with opacity t; that is, these pixels now have transparency 1-t.​

With the mask active, the image looks like this on the screen:

Mask_test_06-03R.jpg

In the circular region, where the mask is only "40% transparent", we see the pixels of the the image there with only "40% opacity"; that is, their "visual potency" is 40% of its natural value.

Correspondingly, the transparency of those pixels (as they participate in the overall image buildup) is 60%.

And as a result, we also see the checkerboard that represents "the great beyond", through those 60% transparent pixels, and thus at only 60% of its natural "potency".

If we save this image as a JPEG file, it will look like this:

Mask_test_06-04R.jpg

We must be cautious here to distinguish between the transparency of the mask in some region with the transparency of the pixels it "lets through" there.

Best regards,

Doug
 

Doug Kerr

Well-known member
Finally, starting with the setup in the previous notes, we place an image layer below the image layer we previously examined (the one with the mask on it). (The simpler mask, without a semitransparent area, is used here.)

The composite image is this (both as seen on-screen and in an output JPEG file):

Mask_test_07-13R.jpg

There are those who say that the action of the mask in this case is to block our view of part of the young lady.

We don't see her where we do see, instead, the pixels from the upper layer, which is in the region where the mask is transparent ("white").

Thus, they say, a "white" region on the mask blocks content.

I do not find that characterization to be attractive. It is based on a "downline" ramification of what the mask actually does to its subjects.

Best regards,

Doug
 
Top