Style: Palettes

Many images we work with in the Style dialog can be made more comprehensible by changing contrast and applying hill shading while leaving the colors in a grayscale range, for example, as shown in the Example: Autocontrast and Hill Shading Images using Style topic.  In addition we can also achieve differentiating visual effects by coloring the pixels using a palette.   Palettes use a single, grayscale color value in a pixel as a lookup index to pick a specific RGB color out of a specified collection of RGB colors.   The collection of RGB colors from which a specific color is picked is called a palette.   This topic provides a tutorial introduction to palettes.

 

We will utilize the same image, providing terrain elevation data in a section of the state of Florida, in the US, that was used in the Example: Autocontrast and Hill Shading Images using Style topic.

il_style_palettes01_01.png

The default image is dark and poorly differentiated.   We will choose Edit - Style to open the Style dialog and then manipulate the image to provide better contrast before we apply a palette.  

 

eg_style01_17.png

 

We check the Common color channel box to combine all the channels together into a single gray scale channel and then we click the Full Range button to utilize the full range of values found in pixels across the common color channel range.  We press Tally, change the last box in the intervals list to white, set the Fill rule to interpolate and then press Apply.

 

eg_style01_18.png

The result is a grayscale image, seen above zoomed out a bit to show more of the terrain, that has reasonable contrast as the values from about 0 to about 92 are assigned to a continuum of grayscale colors from black to white, that is, from 0 to 255.

 

Applying a palette is easy:  We choose the number of Breaks we want (one more than the number of intervals we desire), press Tally to create intervals and then we press the palette button, by default marked Altitude for the first of the pre-loaded palettes.   If we want a different palette than Altitude we first choose that using the pull down menu on the Altitude button and then we press the button.

 

We will apply a palette to the image using ten intervals:

 

eg_style01_19.png

 

We enter 11 into the Breaks box and then press Tally.

 

eg_style01_20.png

 

We click the Altitude palette button to choose that palette.

 

eg_style01_21.png

 

That loads the color values in the intervals list with the colors from the Altitude palette.  

 

As can be seen from the above the Altitude palette provides a fairly typical set of colors that are assigned to various elevations in maps, with elevations lower down being more green and those higher being brown, gray or ultimately, white.

 

The Fill box provides various options for how color values found in the data should be assigned to a palette color if the color value in the data does not precisely match one of the numbers in the palette.   The interpolate fill rule is still active from when we set the contrast.  

 

The default, interpolate option interpolates the range between two colors in the palette.  For example, if we have colors for the break at about 27 and a different color for the break at 36, if we have a data value of 31 the color assigned to that pixels will be about half way between whatever colors in the palette are assigned to 27 and 36.  

 

eg_style01_22.png

 

When we press Apply the palette will be applied to the image.

 

The result is a pleasing rendering.   It shows how we can bring out features by using different colors for different elevation values.   If we would like to adjust the palette that is easy to do.

 

eg_style01_23.png

 

We can click one interval bound and then shift-click another to highlight all intervals between.  We can then right-click onto the highlighted region and choose a modification from the context menu.   For example, we can click reverse to reverse the swath of colors from green to brown.

 

eg_style01_23a.png

 

Press Apply.  

eg_style01_23b.png

The result is a variation on the palette that reversed the group of colors between brown and green without changing the application of the very light colors.

 

If we would like to choose an entirely different palette that is easy to do as well

 

eg_style01_24.png

 

We pull down the menu for the palette button.

 

eg_style01_25.png

 

The palette button's menu includes many ColorBrewer palettes that are named beginning with CB.   These are cool collections of colors that work very well together in various settings.   We choose the CB Set C.

 

eg_style01_25a.png

 

That renames the palette button with the name of the palette it will apply.   We press the CB Set C palette button to apply the palette to the intervals list.

 

eg_style01_25b.png

 

Pressing the palette button applies the CB Set C palette to the color wells in our intervals list.   We press Apply to apply that arrangement to the image.

eg_style01_26.png

It is easy to instantaneously change color palettes.   Note that by applying a palette we are only changing the style of how the image is displayed.  We are not changing the data.

eg_style01_27.png

Different palettes can give completely different visual effects, allowing us to choose what features we would like to emphasize by a clever choice of colors or palette.   The above illustration uses the CB Paired palette while the illustration below uses the CB Spectral palette.

eg_style01_28.png

 

Since we are only changing the style of display, a property of the image and not the data, we can Copy the Florida image component and then Paste it a few times to create additional Florida 2, Florida 3 and Florida 4 images.   Being copies of the original Florida image these all will also take their data from the same table.  

 

We can then open each image in turn and launch the Edit - Style  dialog to change the palette used by that image.

 

eg_style01_29.png

Above we see all four images open in undocked windows in our Manifold desktop, each one using different Style settings.

The StylePixel Property

Once we use Style to assign a palette to an image that palette is stored in JSON format in the StylePixel property of the image.  We can create, delete, copy, paste and otherwise edit that property.

eg_style01_30.png

Suppose we copy the Florida image and then paste it in the Project pane to create a Florida 5 image as seen above.   The pasted copy of course retains the same style that the original image used.

 

A quick way to delete all Style information is to open the image's properties and to delete the StylePixel property.

 

eg_style01_31.png

 

In the Project pane we right-click onto the Florida 5 image and choose Properties   In the properties dialog we click on the StylePixel property to highlight it and then we press the Delete button.

 

eg_style01_32.png

 

The property disappears and we press OK.

eg_style01_33.png

The Florida 5 image now shows the unstyled appearance the image had at the very beginning of this topic.   

 

An easy way to restore style is to simply copy the StylePixel property's value from one of the other Florida images we created in this topic and to then paste that value into a newly-created StylePixel property in the Florida 5 image.

 

We will right-click onto the Florida 3 image in the Project pane and choose Properties.

 

eg_style01_34.png

 

In the properties dialog for the Florida 3 image, we double-click into the value cell for the StylePixel property to open it for editing, do a Ctrl-A to highlight all, and then a Ctrl-C to copy.  We press Cancel to close the properties dialog.

 

Next, we right-click onto the Florida 5 image in the Project pane and choose Properties.

 

eg_style01_35.png

 

In the properties dialog for the Florida 5 image we click the New button to add a new property.

 

eg_style01_36.png

 

We name the new property StylePixel.  

 

eg_style01_37.png

 

We double-click into the value cell for our newly-created StylePixel property to open it for editing, press Ctrl-V to paste what we copied from the Florida 3 properties, press Enter to accept the edit and then OK to close the dialog, saving the new values into the properties for the Florida 5 image.

eg_style01_38.png

Like magic, the Florida 5 image has the style settings applied which we copied from the Florida 3 image's properties and pasted into the Florida 5 image's properties.

 

Properties values for all images, like property values for all other components, are stored in the mfd_meta table.    We can exploit that to copy and paste JSON values for StylePixel from one compatible image to another.

eg_style01_39.png

For example, we can open the mfd_meta table in the Project used for this topic and use Page Down or scrolling or Ctrl-F to find the records giving StylePIxel for Florida 5, as seen above.

eg_style01_40.png

We double-click into the Value cell for the StylePixel property for the Florida 4 image to open that cell for editing.  We press Ctrl-A to highlight all and then we press Ctrl-C to copy.

 

eg_style01_41.png

Next we double-click into the Value cell for the StylePixel property for the Florida 5 image to open that cell for editing.  We press Ctrl-A to highlight all and then we press Ctrl-V to paste.   We then press Enter to close the cell and we press Ctrl-Enter to commit the edit to the table.

 

Important: Do not forget to press Ctrl-Enter to commit an edit to a cell.

eg_style01_42.png

Right away, again like magic, the Florida 5 image takes on the styling that we copied and pasted from the Florida 4 image.

Notes

Compatible images - Copying and pasting JSON strings for the StylePixel property is great, but we should keep in mind that the numbers those styles use should be reasonably compatible with the images into which they are pasted.   If we used Style for an image where values were 0 to 50  for the intervals those Styles will not be very effective for an image where data values are 500 to 5000.

 

See Also

Images

 

Drawings

 

Style

 

Style: Autocontrast

 

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.