Masks

Masks are grayscale images that are used to control other images. Masks are used for two purposes:

·To make a selection in the shape shown by the mask.

·To alter the values in the R, G, B or Alpha channels of the target image using the values in the mask.

A mask can be any grayscale image. There is nothing special about grayscale images used as masks. What makes a grayscale image a "mask" is simply how we use it.

We can create masks using any method used to create or edit grayscale images. Since masks are often used as a means of saving selections or other patterns from existing images Manifold provides an Edit - Save Mask/Channel command that makes it easy to create a mask using an existing image.

Edit - Load Mask/Channel Options

Load

Which part of the image is to be loaded. The selection, a channel, or invisible pixels.

From

The source image to use for the mask. All grayscale images available will be listed together with their sizes.

Mode

Specifies how to use the mask within the target image:

Add - Add the intensity values of the mask pixels to the target.

Invert - If the intensity of a mask pixel is greater than 128, invert the value of the target pixel.

Maximum - Use the maximum of intensity of either the mask pixel or the target pixel.

Minimum - Use the minimum of intensity of either the mask pixel or the target pixel.

Replace - The default. Use the values of the mask pixels.

Subtract - Subtract the intensity of the mask pixel from the target pixel.

Restrict to Selection

If checked (the default), when a selection is present the mask will be applied only within the selected pixels.

Selection using Masks

Masks are a way of using one image to make selections in another image. They are also a handy way of saving as many selections as we like for a particular image by saving the desired selection pattern to a file.

To Create a Selection Mask

1. Make a selection in the image.

2. Choose Edit - Save Mask/Channel.

3. In the Save Mask dialog, save the Selection to an image name.

This creates a new image that has white pixels in the region to be selected and black pixels elsewhere.

If we were to save the selection on the left as a mask the resultant mask image is shown on the right. Once saved, we can subsequently load the mask as a selection at any time we desire.

When we use Edit - Load Mask/Channel to make a selection in the image using a mask it is as if the mask were a cut-out in a sheet of cardboard through which we "spray" selection color onto the image, just like using a stencil.

Choices for Save Mask

When using Edit - Save Mask/Channel to save a mask we have many choices in the dialog's Save box in addition to saving the current selection as a mask. We can also save the mask using:

·The current selection.

·The region of invisible pixels.

·Any saved selection we have made for this image in the Selections pane.

·The R, G, or B channels in the image if it is an RGB image.

·The alpha channel in the image if it is an RGBa image.

Masks created from any of the above can be used to subsequently control the selection; however, when saving the R, G, B or alpha channels the result is most normally used for as masks for channels or to separate the image into different grayscale images for each channel.

Masks are Images

Masks are simply grayscale images like any other grayscale image. They may be opened, edited and otherwise changed as we desire. When used as a selection mask, no selection will occur wherever there is a pure black (value 0) pixel. Pixels in any other color result in a selection being made at that spot. Masks that are used to make selections are usually "painted" in black and white colors even though the full range of grayscale colors may be used. This makes it easy to immediately see what is supposed to be selected and what is not.

Masks that are used to alter RGB or alpha channels are usually gray scale images of various kinds since a range of tones is sought for such purposes. The single value in each grayscale pixel in the range 0 to 255 is used for the value in the target channel.

We can create a new mask image at any time by simply inserting a new grayscale image into the project and then coloring it in black and white to show where the selection should occur. We can then use the "mask" image to make a selection or to control a channel. This allows us to specify regions that are to be selected using the full set of image editing tools within Manifold.

If we create the image at left above we can use it as a mask. Regions of white pixels will be selected. If we open the bronze sample image and use Edit - Load Mask/Channel to load the image as the Selection, we can select a region of pixels in the bronze image in the shape of the word "manifold."

We can create a selection mask by creating a grayscale image that has white pixels wherever we want a selection and black pixels where we do not want a selection. We can also create a selection mask by making a selection in an image and then using Edit - Save Mask/Channel to save it as a mask. We can combine the two methods, by first using Edit - Save Mask/Channel and then opening and editing the resultant mask.

In the example above, we used the Edit - Load Mask/Channel to load the Selection using a mask as a guide. We can also use the Load Mask command to load a channel using the contents of a mask as a guide. Using a mask we can load any of the following aspects of an image:

·The Selection.

·Make the pixels in a given region invisible pixels.

·The R, G, or B channels in the image if it is an RGB image.

·The alpha channel in the image if it is an RGBa image.

Suppose we saved the selection shown at the beginning of this topic as the above mask image, which we called mask1

We can load it into the green channel for the bronze image with the Edit - Load Mask/Channel dialog by choosing Channel: green in the Load box.

This deletes all the previous values in the green channel of the bronze image and replaces it with the "all on" or "all off" values for green the mask specifies.

It is as though we spray-painted green color into the green channel using the mask as a stencil.

When combined with the unmodified red and blue channels in the bronze image the result is the above.

Again, it is as if we deleted all the green from the image and then sprayed pure green color into the image through the mask as a stencil. Note how the clouds are no longer white (because for the most part they no longer have any green color in them. Instead, the clouds are mostly magenta, which is the color that results from mixing bright red with bright blue.

Note that masks don't have to be used only with those images that were used to create them. We can load the sample mask above into the red channel of our sample castle image if we like.

We can use completely new masks that we create on our own with images. Here we have loaded the "manifold" mask shown earlier in this topic as the red channel in the sample bronze image. Note how the clouds now appear cyan, which is the color obtained with no red but very bright blue and bright green.

The illustrations above show simple, black and white masks. Grayscale images can also be used as masks to continuously vary the R, G, B or alpha channel in images.

Using Masks to Specify Alpha Transparency

Masks may be loaded into the alpha channel of images to control transparency.

Using the sample mask we created at the beginning of the topic results in the above pattern of transparency where the image is either fully transparent or not at all transparent.

If we take our sample mask, convert it to RGB, apply Gaussian Blur to blur it, and then convert it back to grayscale we can use it as a mask to create a transitional blend of transparency between fully transparent and fully opaque regions.

The image above shows what happens when we load the blurred mask into the alpha channel. Regions where the mask was completely black have no transparency and are fully opaque. Regions where the mask was completely white are completely opaque. The feathered edges in between where the mask has a blurred gradient of gray tones from black to white now have a blurred gradient of transparency from fully transparent to fully opaque.

One of the most frequent uses of Edit - Load Mask/Channel is to load a grayscale gradient to cause a continuously changing transparency gradient.

We can use the grayscale image of a gradient from black to white shown above as a mask for the alpha channel in our sample bronze image.

The result is a continuous variation of transparency from fully opaque (the white regions of the gradient) to full transparency (the black regions of the gradient).

Using Masks to Specify Invisible Pixels

We can use a mask to specify any regions of invisible pixels.

Suppose we would like the yellow star shown above to shine through our sample bronze image. To do this we will cut out a region of invisible pixels in the bronze image in the shape of the star.

We begin by creating a mask from the star image. To do this we first used Threshold to make the star entirely black and everything else white and then we used Invert to get the above image. This was converted into a grayscale image using Convert to .

We open the bronze image and then use Edit - Load Mask/Channel to load the invisible pixels using the star mask image created above.

The result is a bronze image with opaque pixels in black areas of the mask and invisible pixels in the white regions. The cutout region of invisible pixels is perfectly aligned with the edges of the yellow star because the yellow star was itself used to create the mask.

When we combine the two images in a map with the star image underneath the bronze image the yellow star shines through the bronze image.

Applying Masks only to Selected Pixels

If we check the Restrict to Selection box in the Load Mask / Channel dialog the mask will be applied only to selected pixels if a selection exists.

Let's use the image above as a sample image. We created this image using Image Editing Tools employing a variety of brushes, color and opacity settings. A region in the lower left corner has been selected.

The image above shows a simple mask created using a solid black image to which the Noise effect has been applied. This created an image with speckles of white on a black background.

If we load the Blue channel in the image with the mask using Replace mode (the default), the mask will be loaded only into those pixels that are selected if the Restrict to Selection box is checked.

This works no matter what pixels are selected. In the illustration above we have selected five circular regions of pixels.

If we load the Green channel with the mask with Restrict to Selection checked the mask will be applied only within the selected regions.

Mode Choices

The Mode option in the Load Mask/Channel dialog allows us to choose how we would like the mask to be used in the target image.

The default mode is Replace. Loading a mask with Replace mode means the values in the mask will replace the values for the channel loaded. Note for example in the illustration above how the yellow color in the central circular region has turned red. That happened because the color yellow is a combination of red and green. When loading a mask into the Green channel that has white dots on a black background there is no green value in the black portions of the mask. Where the black portions of the mask replaced green channel pixels no green color is left and so only the red channel is left in what were originally yellow pixels.

Suppose we make a different selection in the original sample image.

If we load the mask into the Green channel using Add mode, note that the yellow pixels are unaffected where the mask is black. That is because black results in adding zero to the green channel intensity. Where the mask has white dots, the yellow is a brighter green-yellow because adding 255 to the green channel forces it to be full green. In the blue pixels of the target image the result is to create bright cyan (blue plus max green) in the spots where the mask has white pixels.

If we use Subtract mode, the values in the mask will be subtracted from the Green channel. There is no change in black parts of the mask since subtracting zero results in no change. In the yellow pixels of the target image, subtracting 255 in those spots where the mask is white results in total absence of Green and thus results in red pixels. Subtracting 255 from the Green channel in pure blue parts of the image has no effect since there is no Green there to begin with. Subtracting 255 from the green parts of the image results in black pixels.

A GIS Example Using Mode

The Mode option to combine a mask by adding it, subtracting it or otherwise combining it in a sophisticated way with an existing channel provides a powerful means to combine multi-spectral images into powerful and highly informative false color images. This example is copied from the Combining Channels into Images topic.

Using a straight, unprocessed combination of the Red, Green and Blue bands from the Landsat 7 Enhanced Thematic Mapper instrument (bands 3, 2 and 1) as the Red, Green and Blue channels in an image results in the muddy and uninformative image above.

We can enhance the image by using a Band 4 image as a mask and using Add mode to add its intensity values to the Green channel of the image. Band 4 is a reflective infrared band that is highly responsive to vegetation. By using it to "kick" the Green channel up we enhance the green element normally associated with vegetation.

We can further enhance the image by using a Band 7 image as a mask and Add mode to add it to the Red channel of the image. Band 7 is a lower mid-infrared band that is responsive to soil types. This lets us see not only vegetation but also soils.

Masks are usually the same size as the image with which they are used. If the mask is larger or smaller than the target image it will be applied centered on the image and all pixels outside the mask will not be changed.

Masks are often created to work with a particular image. For example, one might wish to create a selection mask that selected pixels only to one side of a riverbank in an aerial photograph. There are three frequently used methods to assure that the mask is the same size and otherwise matches positions in the target image:

·We can make a copy of the aerial photograph image and then edit that copy so that all the pixels not to be selected are black. We then convert the image copy to a grayscale image. If desired we can also use Threshold to force all non-black pixels into pure white.

·We can copy the aerial photo image and to position it as a partially transparent layer above the aerial photo image in a map. We can then "trace" the area desired using various editing tools to fill in the region not to be selected with black pixels. Using a map in this way makes it possible to create the selection mask by tracing over the target image as a guide where the guiding image will always be visible through the partially-transparent layer.

·Use the Match command within a map to automatically "cookie-cut" one image with another and to adjust the pixel density and coordinate systems to match.

Invisible Pixels in Masks

Any invisible pixels in masks will not participate in whatever the mask is asked to do. If the mask is loaded as a selection, regions of invisible pixels will not be selected. If the mask is loaded as a channel, any parts of the mask containing invisible pixels will not alter the target image.

For example, when using the mask at left above to select pixels in the image at right above the region of invisible pixels will not result in a selection.

Saving Channels as Separate Images

At any time we can save the separate channels of an RGB or RGBa image as different grayscale images. To do so, we use theEdit - Save Mask/Channelcommand with the channel to be saved specified in the dialog'sSavebox.

See the Separating Images by Channels for a discussion on how Edit - Save Mask/Channel can be used to separate an image into different images for each channel.

Nomenclature

Transparency and opacity are two terms that mean the same concept viewed from different directions. When something is completely opaque it is not at all transparent. When something is perfectly transparent it may be said to have zero percent opacity.

Which word is used depends on the discussion. When imagining layers stacked up above each other like transparent sheets it is conceptually clearer to use the word transparency. When discussing a specific percentage of light transmission to be applied via a slider bar in a dialog most applications use the word opacity.

The convention in the graphics arts editing software industry is to adjust layer transparency with controls that set a number from 0% to 100% opacity, so that an image with 100% will be fully opaque and not allow any view of an image underneath it. Manifold follows this convention. This convention persists in the graphics arts industry even though the technical implementation of transparency effects is done using an alpha channel within RGBa images where the higher the value of the alpha channel (from 0 to 255) the higher the transparency.

One therefore encounters the slight conceptual dissonance of increasing opacity with higher numbers (up to 100%) in dialogs and other user interfaces while the internal data sets use numbers (alpha channel values) in which opacity decreases with higher numbers. Since we rarely set alpha values by hand this is not so bad. Alpha values are normally set using various tools, such as erasers, or masks. In the case of masks, the darker the mask region the lower the alpha value is and thus the higher the opacity. From a casual conceptual view this is very acceptable because it leads to an effect where black regions of masks cause full opacity and white regions of masks cause full transparency. Since we are used to thinking of "white space" as being transparent this works well as a natural mnemonic for the effects of masks.