Example: Set Image Transparency using Alpha

This example continues using the same example data as the Example: Using the Assign Channels Button topic.   See also the Style: Channels and Outputs Tutorial topic.


Color images such as RGB images often also have an Alpha or A output, which specifies transparency for each pixel.   Such images are commonly known as RGBA images.   When an image is imported from a format such as JPG or other format that might not have an alpha channel value for each pixel, Manifold nonetheless is ready to apply a transparency factor to each pixel, a useful capability when the image is seen as a layer in a map.    


The A output row in the Style pane allows us to specify what transparency we want to apply to the image, either by applying the same value for A for all pixels or by using one of the other channels to also control the A value.


Suppose we have a map with two layers, a lower drawing layer that shows shapes colored using thematic formatting in Style and an upper image layer showing the ginevra image.



With the ginevra image clicked off we see the drawing layer.



With the ginevra layer clicked on we do not see the drawing layer because the image is fully opaque.


With the focus on the ginevra layer tab we use the Style pane.  



We double-click into the Value cell for the A row so we can edit the 0 value, to change it to some other value.


 When the row cursor is already on a cell, we can open that cell for editing by simply clicking it.   If the cursor is not on a cell, we can open the cell for editing by double-clicking it.  



We change the Value to 100 and we press Update Style.



A value of 0 for Alpha means no transparency, while a value of 255 would mean zero opacity, that is, complete transparency.   The value of 100 we have applied means about 40% transparency.   That level of opacity allows the drawing below the image to show through the partially transparent image.


We can restore full opacity by changing the Value for A back to 0.



Change the value for A in the Value cell to 0 and press Update Style.



The image is restored to full opacity, that is, zero transparency.


This example uses a simple Value setting to set the same transparency for all pixels in the image.  If we like, we can use a channel to control alpha transparency.   See the Example: Assign Channels topic and the Knock Out Pixels Using Join and Alpha  video for examples.

Applying Changes in Alpha to Linked Data

When working with spatial data we may find the Alpha setting useful to show displays from more than one data source.  The steps which follow are somewhat contrived, in that the usual way we would change transparency of layers in a map is using the Layers pane.   However, changing transparency using the Layers pane only changes transparency for that layer in that particular map.   Changing the alpha channel is changing a property of the image and will apply in whatever setting that image is used.



In the illustration above we see shaded terrain elevation data, in the region just to the East of Huckleberry, Maryland, from a server in Maryland as shown in the Example: Autocontrast and Hill Shading Images using Style  topic.


We create a new data source using the Bing street map image server as shown in the Example: Create a New Data Source from a Manifold Image Server  topic.   


Important: We then create an editable copy of that image as shown in the Example: Style Applied to an Image Server Image topic, and then we drop that editable copy of the image into the map.  This is an important step because images within the Bing data source are read-only, so if we want to change the Style used by that image we must first copy the image within the Bing data source, paste it as read/write image outside of the data source, and then adjust the properties to point back at the tile table that Bing provides.  This sound more complicated than it is in real life, where only a few moments are required.



The image server layer is opaque, so we can no longer see the LiDAR data image below it.    We click the image server layer to make it the active layer and then we use the Style pane.



We see that the images provided by the Bing image server are RGBA images, that is, they have a fourth channel, Channel 3, that is used for A or Alpha.   We double-click on the A output row's channel cell.  



We want to apply the same, fixed value for Alpha for all pixels so in the pull-down menu we choose Value.  



We then double-click into the value cell, and enter a value of 100.  Press Update Style.



The result as seen above is that a transparency value of 100 is applied to all pixels in the image server layer, allowing the LiDAR layer beneath it to show through.


Alpha channel or Layers pane? -  In this example, we show how to vary the transparency of an image by altering the Alpha channel for each pixel.   That is a different technique than using the Layers pane to change the transparency of a layer in a map.


Changing transparency using the Layers pane only changes transparency for that layer in that particular map.   Changing the alpha channel is changing a property of the image and will apply in whatever setting that image is used.


Opacity or Transparency? - Alpha channels may be interpreted as setting either opacity, or transparency.   When an alpha channel sets opacity, a high value in the channel means greater opacity, with a value of 255 meaning completely opaque and a value of 0 meaning totally transparent.   When an alpha channel sets transparency, a high value means more transparency.  Some formats, such as TIF images, specify alpha as opacity, so that is how Manifold imports alpha channel data for TIF, interpreting 255 as full opacity.    Other packages and formats use transparency for alpha, and sometimes alpha data in TIF is stored using transparency.    The default setting for internal use by Manifold is to interpret alpha as transparency, as is shown above in this topic.


If alpha data is ever imported and is flipped from how it should be, using transparency instead of opacity or vice versa,  and the reverse is required, that is easy to arrange using Manifold's automatic inversion capability, as discussed in the section titled  Example: Automatic Inversion in the Style: Images topic.


Download the full size ginevra image from the Product Downloads page.


See Also



Images and Channels


Palette Images




Style: Images


Style: Channels and Outputs Tutorial


Style: Autocontrast


Style: Palettes


Example: How Images use Tiles from Tables - An example showing how an image is made up from data stored in a table in tiles.


Example: Create Two Images From One Table - More than one image can show data from the same table, including from the same tile field.


Example: An Image using Computed Fields in a Table - How an image can be created from tiles where the data for the tiles is taken from a field that is computed on the fly.


Example: Change the Contrast of an Image - In this example we use the Style pane to change the contrast of an image.


Example: Using the Assign Channels Button - The Assign Channels button in the Style pane for images allows us to assign channels to the standard three Red, Green, and Blue display outputs using frequently-desired arrangements.   The button provides a short cut way to assign all channels at once instead of doing each channel individually.


Example: Assign Channels - How to use the Style pane for images to assign channels to display outputs such as R, G, B or A.  This topic shows examples of channel combinations and the visual results.


Example: Display an NAIP Four Band Image as Color Infrared (CIR) - How to use the Style pane for images to re-assign channels in a four band NAIP image to produce a Color Infrared (CIR) image display.


Example: Autocontrast and Hill Shading Images using Style - This example shows how the Style pane can hill shade an image using the values of pixels as heights and generating shadows as if the Sun were located at the specified azimuth and altitude.   This capability is used most frequently with raster images to give an impression of three dimensionality in cases where the values of pixels represent terrain elevations.


Example: Style Applied to an Image Server Image - Because the Style pane simply changes the way an image is displayed and not the data, it can operate on read-only data served by various web servers such as WMS REST servers.    In this example we look at every detail of creating a data source using an image server and then manipulating the appearance of the display with Style.  We will connect to a WMS server that provides LiDAR data in various forms, including as terrain elevation.