Hexagon Geospatial
MENU

Spatial Recipes

The IMAGINE Spatial Modeler provides the user with hundreds of functions, algorithms and analytical routines that can easily be chained together into models that solve Geospatial problems.
Showing results for 
Search instead for 
Do you mean 

Apply a fixed value mapping Color Ramp

by Technical Evangelist ‎12-06-2017 09:23 AM - edited ‎12-06-2017 11:22 AM (397 Views)

 

Download model

 

Description:

 

Two 2D Views showing the same dataset, but Gray Scale on the left and Pseudo Color on the right (with ETrF color ramp)
ETrF_1.png

 

I was once asked the following by a customer:

 

"Color coding images is a pain.  It would be great if we could make a legend and then apply it to the image, instead of having to select and code groups of colors for each image individually, just because the range of values are slightly different.  For example, I have a model that outputs an ETrF float image that needs to be color coded as follows:

 

  • ETrF -0.25 or less, Red
  • ETrF -0.25 to 0, Red to Beige
  • ETrF 0 to 0.25, Beige to Tan
  • ETrF 0.25 to 0.5, Tan to Turquoise
  • ETrF 0.5 to 0.75, Turquoise to Chartreuse
  • ETrF 0.75 to 1.0, Chartreuse to Dark Green
  • ETrF 1.0 to 1.25, Dark Green to Blue
  • ETrF 1.25 and more, Blue

But the actual range of image values is slightly different for each ETrF image, so I have to open raster attributes, select values, and input the colors, for each image individually."

 

Which is entirely true. But with the release of ERDAS IMAGINE 2016 there was a solution to this in the form of the Create Color Ramp operator.

 

But first, let's look at the ways of defining display colors for pixel DN values. For a Thematic (e.g. Landcover Classification) this is straightforward. When the image in opened into the 2D View it will (generally) default to Pseudo Color display mode. In this mode the Raster Attribute Editor panel can be brought up and colors set for each DN value / Class. This process can even be automated using the Spatial Modeler through approaches similar to this Spatial Recipe

 

But if the image is a continuous, Athematic image, such as an NDVI, or an ETrF, or even a DEM, the approach is a little more complicated. When such an image is displayed in a 2D View it will default to Grey Scale mode (similar to the display shown in the left-hand 2D View of the screenshot above). In this mode the Raster Attribute Editor cannot be used to affect the "color" of the display, since this display mode is intended for grey scale display, controlled by a Lookup Table (LUT), instead. However, an Athematic image can still be displayed in Pseudo Color mode. When using the FIle Chooser to select the input file a second tab will be available called Raster Options. On this tab the Display mode can be changed from the default Grey Scale to Pseudo Color. Click OK and the data will be displayed. Now the Raster Attribute Editor panel can be displayed and colors can be assigned to DN values.

 

Raster Options tab of the File Chooser
ETrF_File_Chooser.png

 

Color ramps can also be quickly assigned in this mode. The Colors button on the Table tab brings up a dialog from which various color ramps can be applied to the selected range of data.

 

However this is where we encounter the problem mentioned by the customer above. Applying a color ramp (e.g. Violet through Red) to the full range of DNs values is straightforward. But if you have to manually select a range (e.g. -0.25 to 0), apply a ramp (e.g. Red to Beige), select another range (e.g .0 to 0.25), apply a different ramp (e.g. Beige to Tan), etc., it becomes tedious (especially if you have to do it on more than one image).

 

There's also the problem of the start and end data range of the image being analysed, even if applying a single ramp across the full range. You might want a Violet to Red ramp on your data products and that can be easily applied using a Spatial Model. But it's generally applied across the full range. So if one dataset starts at 40, the color ramp would start with Violet for DN 40 and go up from there. But another dataset might start at DN 80, meaning that Violet would be assigned to DN 80. The problem this causes is lack of consistency and interpretability - you can't look at two color-coded images and know that the color Violet represents a value of 40 in both images.

 

Which is exactly what's needed for the ETrF problem presented. The color Turquoise has to represent an ETrF value of 0.5.

 

Which bring us to our new Spatial Model using the Create Color Ramp operator introduced with ERDAS IMAGINE 2016.

The Create Color Ramp operator provides a means to set a direct relationship between a DN range and a color range. So we can, for example, define that a DN range of -0.25 to 0 should be portrayed as a color ramp between Red and Beige. It also enables several such discrete ranges to be cascaded together to define the various color transitions to apply over a much broader range of DN values, such as those defined in the ETrF example above.

 

ETrF_Color_Ramp-v16_1_1.gmdx
ETrF_Model.PNG

 

The result of the chain of Create Color Ramp operators is a Color Table which can be attached to a raster dataset so that when it is displayed using the Pseudo Color display mode it is colored in the desired manner.

 

Creating a Spatial Model of this nature thereby enables a standardised "DN to Colors" ramping to be created, which can be applied consistently to multiple datasets quickly and easily.

 

 

Assumptions:

 
The model provided applies the color ramp(s) appropriate to an ETrF dataset. Such a dataset is usually a floating point dataset with a range 0 to 1 (with the possibility of values outside that range due the vagaries of data processing). As such, the model is implemented to apply color ramps designed for this type of data. To apply this to other datasets you may need to add or remove Create Color Ramp operators and define the DN ranges (and colors) they apply to, as appropriate.

 

This type of model can be embedded into a larger model (such as one which calculates ETrF) so that the datasets produced have an appropriate color ramp embedded in them at the time of creation.

 

Input parameters: 

 

Input Image: Input image filename to assign a color ramp to.

Apply to Input Image?: If set to Yes / True / 1, the color ramp will be attached to the Input Image (and no output file will be created. Otherwise (No / False / 0) a new Output Image, with the color ramp associated to it, will be created.

Output Image: Name of the new, output image file to create if "Apply to Input Image?" is set to False.

 

ETrF_Run_Dialog.png

   

 

 

 
Overview
Contributors