Example: Autocontrast and Hill Shading Images using Style

The Style panel can hill shade an image by interpreting the color values of pixels as heights.  The system can then alter the display, darkening some pixels, to give the appearance of shadows as if the Sun were shining on a three dimensional surface.   This capability is used most frequently with raster data where the values of pixels represent terrain elevations, so the resulting impression of three dimensionality provides a realistic effect.  Shading can also be used to generate distinctive visual effects in images where pixel values represent something other than terrain elevations.  For example, if raster data shows temperatures in a given region, visualizing those temperatures as if they were hill shaded highs and lows can provide a more comprehensible display.

 

In this example we will use data where the value of each pixel represents the average elevation of the terrain in the region covered by the pixel.

 

We have imported raster data from a file that gives terrain elevations in a region of the state of Florida in the US.   As with all raster data the data is kept as records in a table where each record contains a tile of data.

 

eg_style01_00a.png

 

We double-click open the Florida Table component, which is the table with data that is visualized in the Florida image, to see what data type is used for pixels within the tiles.

 

eg_style01_02.png

 

Each record has a tile made of up 128 x 128 pixels, that is, 16384 pixels, with each pixel consisting of a single, float32 value.

 

eg_style01_00.png

 

Double-clicking on the map into which we previously have dropped the Florida image opens the map in a window.

 

eg_style01_01.png

 

The map has one layer in it, the Florida image.   What we see initially is not all that impressive.  It is an image composed of tones of black and very dark gray that are so similar to each other and all so dark it is difficult to make out any features.   When importing terrain elevation data, Manifold will often present a very good image by default.  We have deliberately chosen an example where the data is muddy and difficult to discern, so we can show how easy it is to create a more understandable display.

 

The problem with the display above is that contrast is poor, a typical situation in terrain elevation data where all of the elevations are similar.   We are looking at a section of central Florida, an exceptionally flat region, where all of the elevations are a few meters, or feet, of each other.   We can provide a better display by using the Style panel to increase contrast.

 

There are two ways to apply contrast to the image: a quick way to provide a visual impression that looks good, but is less useful in the long run, and a longer way that ultimately will be more useful with terrain elevation data.

A Quick Impression

In a few seconds with a few clicks we can provide a good visual impression with better contrast.   In the Contents pane we choose the Style panel.

 

eg_style01_03.png

 

The Style panel shows the R, G and B outputs used to form an image on our monitor and it tells us what data is used for each output.   When a data set has only one numeric value per pixel that same numeric value is used to drive all three outputs.  The panel shows how a single channel, Channel 0, is used to drive the R, the G and the B output.    

 

When the same value is used for all three display outputs the result is a range of gray shades, from black when the value 0 is used for all three outputs to white when the value 255 appears in all three outputs.  The 0 to 255 values are the possible range of values given the data type.  That does not mean that within the image we will find pixels with all of those values, it just means that given the data type the values could range from 0 (black) to 255 (white) or numbers in between (various shades from very dark to almost white gray).   Given that most of the altitudes in this region of Florida are well under 90 meters (the data set uses meters), the resulting tones are all in the zero to 90 range, from mostly near black to dark gray.

 

eg_style01_04.png

 

To automatically apply contrast, we Ctrl-click each of the rows to select them, and then we right-click into one of the 0 to 255 range boxes.   We selected the three rows so that whatever we apply to one of them will apply to all three at once.  

 

eg_style01_05.png

 

In the pull down menu that appears, we choose Autocontrast and then an autocontrast spread of 2.0 standard deviations, which usually works well.

 

eg_style01_05a.png

 

The autocontrast computation resets the 0 to 255 range values for Channel 0 to the approximately 1 to 47 values which span two standard deviations.   We press Update Style to apply the changes.

 

eg_style01_05b.png

 

Immediately, we see an image with much better contrast.   Numerous geographic features are now visible.  The enhanced contrast is achieved by using pixel values within two standard deviations, a range from about 1 to 47 and stretching that range to fill the 0 to 255 range of available display intensities.  Pixel values in the data set above 47 are forced to 255, that is, displayed as white and pixel values below 1 are forced to black.  

A Longer, More Useful Procedure

What is wrong with the previous procedure is that we are pretending the image is an RGB image that is fed by three channels.  That is a good approach sometimes for creating false color images, but usually treating the image for what it really is, a terrain elevation data set driven by a single channel, is a better approach.   That allows us to use hill shading and palettes to color-code terrain elevations using discrete intervals of height, with a different color for each height interval.

 

eg_style01_03.png

 

Assume we start at the beginning with the Style panel as seen above.

 

eg_style01_05c.pngeg_style01_06.png

 

Instead of using RGBA channels, in the pull down menu we choose Channel 0.    The panel immediately switches to controls used with a single channel, basically a palette image.

 

eg_style01_06a.png

 

Using equal intervals, we change the number of Breaks to 2 and we press the Tally button.    We double-click into the color wells and set the upper color well to black and the lower color well to white.  The Fill color will be remembered from our prior use of the panel.   We make sure Fill is set to interpolate.   With those settings we press the Update Style button.

eg_style01_07.png

 

That provides an immediately more understandable display, revealing the Lake Wales Ridge of higher territory that runs vertically down the central region of Florida.    The highest location seen is Iron Mountain, near Lake Wales, not much of a "mountain" at only 90 meters above sea level, but it is dramatically higher than an otherwise very flat and low central Florida.

 

eg_style01_07a.png

 

We can increase contrast even more by double-clicking into the lower value interval and changing the value to 47, thus forcing terrain values higher than that into the white interval.  We press Update Style to apply the change.

 

eg_style01_07b.png

 

Right away, the contrast increases.

Shading

Our next step is to apply hill shading.   In the Options tab we check the Use shading box, an option which is only enabled if we are using a single channel.   It is not enabled when using RGBA channels.

 

eg_style01_08.png

 

We use the default settings and press Update Options to apply shading.

 

eg_style01_09.png

 

The system immediately shades the terrain, as if was illuminated by a light source at a 45 degree azimuth elevation and placed at a compass bearing of 315 degrees.   We are zoomed far out so the terrain is less crisp than when seen closer up.   We can zoom in for more detail.

 

eg_style01_09b.png

Zoomed in, we can see more details, and more detailed hill shading.    In the illustration above we used a Z scale value of 1.   For this particular data set that results in more emphatic shading effects.   We can reduce the shading effect by using a lower Z scale value.

 

eg_style01_08a.png

 

For example, we could change the Z scale value to 0.5 and then press Update Options.

 

eg_style01_09a.png

That will produce a softer shading effect, because the shading will be computed as if the terrain were half as vertically high than with a Z scale of 1.  We often will adjust Z scale in various data sets as we zoom in or zoom out to get exactly the effect we want.  

 

Applying a Color Palette

We mentioned earlier that using a single channel was more productive in the long run for terrain elevation data, because a palette could be used.  Let us now apply a palette.

 

eg_style01_10.png

 

We change the number of Breaks to 6 and then we press the Tally button.   That computes intervals which are loaded with black color by default.   To fill those intervals with a color palette, we click the Palette button.

 

eg_style01_11.png

 

In the palette button menus, we choose the Color Brewer CB Accent palette.  If we are happy with this palette at this point we could just click the Update Style button and we are done.   Easy!  

 

However, from experience with this data set we know we would like to apply the CB Accent palette, but in reverse order.  Doing that is easy.   We click into the intervals panel to move the focus there and then we press Ctrl-A on the keyboard to select all of the intervals.

 

eg_style01_12.png

 

The intervals appear in red selection color to show they all have been selected.  We right-click onto any of the color wells and choose Reverse from the context menu.

 

eg_style01_12a.png

 

That reverses the order in which colors are applied.  We press Update Style.

 

eg_style01_12b.png

 

Instantly, Manifold applies the palette to the intervals specified, interpolating colors for pixel heights.    We have applied a color palette, but we are still using just a single height channel so we can hill shade if we like.

 

eg_style01_13.png

 

In the Options tab we check the Use shading box, enter a Z scale of 0.5 and then we press Update Options to apply shading.

.

eg_style01_14.png

 

The result is a display that is colored by height of terrain and is also hill shaded.

 

Only the Display is Changed - Not the Data

In all the above it may look like pixel values have been modified but they have not.  Only the display has been changed with computations necessary to show pixels as if they had different grayscale values done on the fly.   The data in the table has not been modified.   We could save the project, copy the saved project file to a USB drive, take it halfway around the world, open it on another machine and then by unchecking the options specified see the data is exactly the same as it originally was.  

 

That is a very different situation than graphics editing packages such as PhotoShop, where if we change the contrast in an image the actual data in the image is changed.  If we change the contrast of an image in PhotoShop, save it to a file and then send that file to someone else that other person could open it and see an image as edited by us, but they would have no way to know what the original file looked like.   Many other GIS packages will also change the actual data if we make modifications such as changing contrast or altering pixel colors to give the appearance of hill shading.   Manifold's ability to change contrast levels or to show hill shading in a display without changing the underlying data is an extremely useful capability.

 

To demonstrate that Manifold does not alter the underlying data but only changes the style of display, we will now use the Style panel to restore the display options back to their original form.

 

eg_style01_15.png

 

The quickest way to do that with this particular image is to choose (use RGBA channels) again.

 

eg_style01_15a.png

 

We press Update Style.

 

eg_style01_15b.png

 

Right away, the Style panel returns to the starting state.

 

eg_style01_16.png

 

The image also returns to the initial display.   

 

 

Notes

 

Lake Wales Ridge - The data used shows the Lake Wales Ridge of Florida, which at a maximum height of 92 meters is one of the highest locations in central Florida.  

 

See Also

Images

 

About Images,

 

Images and Channels

 

Palette Images

 

Style

 

Style: Images

 

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 panel to change the contrast of an image.

 

Example: Using the Assign Channels Button - The Assign Channels button in the Style panel 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: Set Image Transparency using Alpha - The A row in the Style panel 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.  An example includes applying transparency to an imageserver image.

 

Example: Style Applied to an Image Server Image - Because the Style panel 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.