Example: Autocontrast and Hill Shading Images using Style

The Edit - Style dialog 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.   But shading can also be used to generate distinctive visual effects in images where pixel values represent something other than terrain elevation.  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've imported raster data 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.




We can 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.




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.




Double-clicking on the Florida image opens it in a window.


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 close together and dark it is difficult to make out any features.   The Edit - Style dialog can show us what is going on and it allows us to alter how the data is displayed to make the image more understandable.




The Style dialog show 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 dialog shows that by citing Channel 0 is used to drive the R, the G and the B outputs.    


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).




To simplify the display and to enable hill shading, we will check the dialog's Common color channel box.   That collapses the four separate rows for the R, G, B and Alpha outputs shown in the dialog into a single, combined line.  Checking the Common color channel box also will enable controls, such as the Shading control, that can only work when there is a single value for all outputs.




We press the Autocontrast button to compute the autocontrast Range using an Autocontrast spread of 2 standard deviations, which usually works well.




Next, we enter 2 as the number of Breaks (we want only one interval) and then we press Tally to update the intervals list using the Range values computed by the Autocontrast button.




We double-click into the lower color value box to change it to white.




We change the Fill rule to interpolate.  


So far we have computed a range of values that fit into 2 standard deviations, a good range to stretch out into the full display output range of 0 to 255 to get better contrast.  We have assigned all those to a single interval which starts with a black value and ends with a white value and we have instructed the system to interpolate color values in between, that is, use a gray scale for colors between black and white.




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.  


Press Apply and the result is a far more understandable visual display.   Now we can see drainage channels and circular lakes or ponds.  


Our next step is to apply shading.   We check the Shading box ...




... and click Apply.



In the illustration above we used a Z scale value of 1.   For this particular data set that results in higher contrast for shading effects.   We can reduce the contrast by using a lower Z scale value.




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



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

Sun Azimuth and Altitude

The default hill shading gives a 3D effect as if the terrain were elevated according to the values used for pixel grayscale, with the Sun shining from a direction of 315 degrees, that is, from the upper left, and at an altitude of 45 degrees, that is, about half-way up from the horizon to directly overhead.   


The illustration below shows the imaginary placement of the Sun for the computation of shading effects, within a synthetic 3D view of the terrain (using greatly exaggerated differences in elevation, necessary since Florida is so flat...) as if we were flying over the region above one of the round ponds near the center of the image and looking North.




For most people, applying hill shading with the Sun apparently shining from the upper left of the view provides the easiest to "read" view of shading where hills appear to pop up and depressions (such as craters) appear as low places. This avoids a false reading of shading effects such as sometimes happens when looking at photos of the Moon in which craters appear to be round mounds instead of depressions.   Many hill shading packages therefore use defaults of an azimuth of 315 and an elevation of 45 even though in many parts of the Northern hemisphere the Sun is always South of the line from East to West.  


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 display 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 a capability few other packages have.


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




We begin by unchecking the Shading box and then pressing Apply.


The hill shading effects immediately go away.




Next, we will restore the use of the full range of pixel color values instead of the clipped and stretched range of values resulting from Autocontrast.   To restore the full range of values we simply press the Full Range button.    Note that before pressing the Full Range button the range of pixel values stretched into the available display range was from about 1 to about 47.




We press Tally to recompute the interval list.




In the new list we double-click into the lower box to change it to white, also making a mental note to send in a request to have that done automatically for single-channel images.  There is no need to change the Fill rule to interpolate as the dialog remembers that setting from our earlier use of it.




After pressing the Full Range button the range has expanded to all the values found for pixels in the data, from about 0.29 to about 91.7.   We press Apply ...


... and the result is an image showing what the data looks like when the range of values in the data, from around 0 to around 92 is smoothly interpolated into the available display range of 0 to 255.   That is a form of slight contrast stretching in that a tighter range of values that look more like each other is expanded to use a wider range of display values where the gray tints are more different from each other.


If we do not want that interpolation and prefer to see the data in a straight, one-to-one association between the data value for a pixel and the resultant display level we can simply assign the values to be used to range from 0 to 255.




We do that by entering 0 and 255 in the boxes for the Range.   We then press Tally to recompute the intervals list.




As before we double-click into the last box to change it to white.




 We then press Apply to apply the changes we have made to the display.


The result is the original display we saw when we first opened the image.   All of the grayscale colors in the image are taken directly from the data.  Because the values in the data range from about 0 to about 92 all of the display intensities also are in the range from about 0 to about 92.  That means the image is dark and contrast is low since most of the values result in dark grayscale colors that are visually similar to each other.



Hill shading only makes sense for elevations or similar - In the examples above once we apply a palette to an image we will have colored the image's pixels using the colors in the palette.  We could still check the Shading box if we wanted but that would no longer make sense as the values shown in the pixel will now be RGB colors that no longer have brightness values corresponding to elevations.   The shading will end up being a strange mush of effects and not elevation shading.


See Also



Images and Channels


Palette Images




Style: Presenting 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 Edit - Style dialog to change the contrast of an image.


Example: Use the BGR Button to Assign Channels - The BGR button in the Edit - Style dialog for images allows us to assign channels in the data to B, G and R outputs that create the displayed image, using BGR, RGB or Grayscale ordering.


Example: Set Image Transparency using Alpha - The A row in the Style dialog 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 Edit - Style dialog 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.