The Style dialog allows us to set contrast for any data channel used in an image or for all of the channels combined into a common color channel.
We know instinctively what a contrast setting does visually from having used it with graphics editors, where the difference between darker and lighter pixels is accentuated. Contrast can be improved by recalculating the values used for display from the values in the data so that in some cases light pixels are even lighter and dark pixels even darker.
Consider how contrast works for grayscale images: In a grayscale image pixels can have a grayscale color value from 0 to 255. If the values in the data tend to be spread out across that range using the full range of values from 0 to 255 to "paint" an image then features shown in different grayscale colors will tend to have good contrast, because there will be a big visual difference between very bright pixels with high values like in the 250 to 255 range and very dark pixels with low values from 0 to 5. We can see this effect with a simple experiment.
Imagine an image that was created from pixels with grayscale color values that are all similar to each other, such as a range of grays from 120 to 150, where a line of pixels using the lighter gray color 130 would appear against a slightly darker background gray color made up of pixels in color 120, as seen below.
The visual difference between those two different shades of gray is very small so there is little contrast between the line and its background.
There would be much greater contrast between the line and the background if the line were pure white, using a value of 255 against a background of pixels colored in pure black with a value of 0. If we had an image where a line of pixels using color 130 appeared against a background of color 120 we could increase the visual contrast in the image dramatically by displaying those pixels on a monitor as if the pixels which had a value of 130 instead had a value of 255 and as if the pixels which had a value of 120 instead had a value of 0, as seen in the image above. This is an example of stretching the range 120 to 130 to fit into the range 0 to 255. It is increasing the ten color difference in the range 120 to 130 by a factor of twenty five into the range 0 to 255 where the two colors in use are two hundred fifty five colors apart, a much bigger difference.
Although the greatest visual contrast is between the extremes of black and white we do not usually want to display a data set with a range of grayscale colors so that all of them are forced to be either totally black or completely white. Sometimes we might want to do that but usually that is too harsh, a too extreme an application of enhanced contrast. Instead, we normally would like to pick out which range of pixels will be adjusted and how that range will be stretched to give greater differences between colors in the range. Mathematically a standard way of picking out a range of pixels to adjust for contrast purposes is to consider the standard deviation of the values which appear in pixels in the data set.
Let us see how that works with an example image, the terrain elevation data for a section of Florida that is used in the Example: Autocontrast and Hill Shading Images using Style topic. When we first open the image it is dark overall and has poor contrast.
Why is the image so dark and with such poor contrast? The values in the pixels for this data set are heights of terrain in that part of Florida, which ranges from about 0 to about 92 in height for the region shown. Because the values in the data range directly drive the display outputs, that means data values in the range from about 0 to about 92 result in grayscale output values in the range from about 0 to about 92.
A grayscale value of, say, 60 for a pixel means that the terrain in the region covered by that pixel is about 60 feet above sea level (the data set is US data that uses feet instead of meters). That part of Florida, like most parts of Florida, is rather flat with very little difference in the height above sea level in various parts of the terrain.
If we simply use the height above sea level directly as a grayscale color the result therefore is an image that has very little difference in the gray colors used in the image, that is, very little contrast. Because Florida is not only flat but also very low near sea level in most regions, the heights are also low values, which means dark colors when those low values, such as 60, are used as grayscale colors.
Because the values in the data range directly drive the display outputs, that means data values in the range from about 0 to about 92 result in grayscale output values in the range from about 0 to about 92, all of which are darker shades of gray.
There are no brighter shades of gray such as those we might see if pixels had values from around 150 or so all the way to white at 255. The image is dark and contrast is low since it consists of dark, grayscale colors that are visually similar to each other. In general, an image that is formed from pixels that all fall within a narrow range of brightness within the possible range will have low contrast.
To create a brighter image with more contrast we must emphasize the differences in heights, and thus colors, by increasing them from a range from 0 to 92 to a bigger range, from 0 to 255. If we take a range of pixel values from 0 to 92 and display them as if they were multiplied a bit to give a bigger range, from 0 to 255, we would increase the brightness difference, that is the contrast, between the darkest pixel and the lightest by about two and a half times.
We can do that easily using the Style dialog. With the focus on the opened window we choose Edit - Style to launch the Style dialog.
When the Style dialog opens we see at a glance that a single channel, data Channel 0 drives all three R, G and B display outputs. Channel 0 is applied to all three display outputs since this image is raster data in the form of a single data channel that represents terrain elevations in Florida. Right away that tells us we can work more effectively by clicking the Common color channel box to manage how that single channel feeds all three outputs at once.
We want to increase contrast so we begin by pressing the Autocontrast button.
The default value of 2 in the Autocontrast spread box specifies two standard deviations, stdev, worth of pixel data values. As a rule of thumb using two standard deviations tends to give a good visual effect. When we press Autocontrast the Style dialog will compute the data values within Channel 0 which fall within 2 standard deviations and will load the range boxes with the lower and upper bounds of that range.
In the earlier discussion above we discussed taking the Channel 0 values from 0 to 92 and displaying them as if they were interpolated into a bigger range, from 0 to 255.
That would indeed give a better effect but we can do an even better job of increasing contrast by just taking the pixels in the two standard deviations of values that make up most of the image, roughly from 0 to 50, and displaying them as if they filled the range from 0 to 255 from black to white. That is a stretch that is roughly a factor of five increase in the difference between the darkest pixel and the lightest, giving much greater contrast.
From the above illustration we see that the values in data Channel 0 which fall within 2 standard deviations range from a low of about 1 to a high of 47.
To build intervals we change the number of breaks to 2 and press the Tally button [upcoming Manifold updates will simplify this step].
We then click into the bottom color well to change it to white [upcoming Manifold updates will simplify this step].
We choose interpolate for the Fill rule [upcoming Manifold updates will simplify this step].
We can now press Apply.
When we press Apply, for display purposes that range of values from about 1 to 47 will be shown as if those values filled the range from 0 to 255. Any pixel value above the two standard deviation range will be forced to 255 and any below will be forced to 0. Those pixels within two standard deviations (in this case being values from 1 to 47) will be proportionately interpolated into display outputs as if they filled the range from 0 to 255.
That will increase the difference in brightness between the darkest and lightest pixels in that range by over a factor of five, greatly increasing contrast. Two standard deviations covers most of the pixels so relatively few will be forced to totally white or black, avoiding garish effects.
Press Apply and the result is a better visual display with more contrast.
Suppose we had used only 1 standard deviation as the Autocontrast spread value?
We change the Autocontrast spread value to 1 standard deviation and then we press the Autocontrast button to compute the new ranges.
1 standard deviation includes only those pixel values in the middle of the range, from about 12 to about 35,
The number of breaks is still 2, remembered from the previous step. We press the Tally button [upcoming Manifold updates will simplify this step].
We then click into the bottom color well to change it to white [upcoming Manifold updates will simplify this step].
The Fill rule of interpolate is remembered from our previous work. We click Apply.
The result is too much contrast with too many pixels forced to white or forced to black. One standard deviation includes pixel values in the range from about 12 to about 35, a tight range of pixels that leaves many pixels above 35 to be forced to 255, pure white, and many pixels below 12 to be forced to 0, black.
What would happen if we chose 6 standard deviations as the Autocontrast spread value?
The illustration above shows the Style dialog after we have changed the Autocontrast spread value to 6 standard deviations, pressed the Autocontrast button, pressed the Tally button, etc., and are ready to press Apply.
6 standard deviations is such a wide range of pixels that it includes almost all pixels within the data set. Pixel values from about 0 to almost 92 are interpolated into the range of 0 to 255, an increase in brightness difference of about two and a half, with so few pixels forced to white or to black that pure white and pure black regions are not visible. The resulting contrast level is less than we would like.
Style: Formatting Drawings and Labels
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.
Example: Autocontrast and Hill Shading Images using Style - This example shows how 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.
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.