Module Colorize
See also
opals::IColorize

Aim of module

Generates and exports colored visualizations of point cloud attribute (ODM) or raster models.

General description

The module creates color coded data sets of point clouds (ODMs) and grid model files which help interpreting the content of the input source. The colorization can be done for one, two and three input channels revealing complex relations of the input source. Input channels correspond to coordiantes and attributes for ODMs and raster bands for grid files. In the grid file case, the module always creates a new color coded raster file. For ODMs, on the other hand,
two different output modes are implemented. The color values can either be directly stored within the ODM (standard case) (in the predefined attributes Red, Green and Blue) or a LAS-File containing the RGB-values (using Point Data Record Format 2) is created. In the latter case, the ODM is opened in read-only mode and stays unchanged.

Basically, coloring is a classification task dividing values into distinct classes and assigning a specific color to each class. Thus, the process can be split up in two parts: the definition of classes and the assignment of color values.

The main instrument for controlling both, the class definition and color assignment is the palette file (see Palette File Format, parameter palFile). Palette files always map the entire value range from - \(\infty\) to + \(\infty\), thus, the general form of the palette file is:

Index Color Remark
- \(\infty\) color0 underflow color
index1 color1 index1 = index min
index2 color2
 ...        
 ...        
 ...        
 ...        
indexn colorn overflow color, index n = index max

The palette file can be seen as a step function mapping values (index) to colors (value). Thematic maps mainly using irregular class boundaries (e.g. traffic-light-maps indicating good-medium-bad quality, maps of laser scanning strip differences indicating areas with good or bad consistency) can be derived easily that way. No interpolation of intermediate colors is performed as the classes of the output raster file exactly match the classes of the palette file. Another standard application is the derivation of color coded maps using continuous/equidistant classes and smooth color transitions. Therefore, additional parameters are provided to overrule the class division as given in the palette file. Equidistant classes can be defined by specifying a class interval (parameter interval) or a desired number of classes (parameter nClasses). In this case the palette is interpreted as a piecewise linear function and intermediate colors are interpolated in the center of each class to get a look-up-table. This is the intended way for deriving e.g. hypsometric views of the terrain.

By default, the indices of the palette file equal the values of the input channel. This transfer functions can be adapted by the optional parameter scalePal for each input channel separately. Linear transformation using offset and scale, linear stretching but also non-linear transformations like histogram equalization are supported. Necessary values can be either specified as absolute or percentage values as shown in the example section. Please note that multiple values have to be separated by comma and MUST NOT contain whitespaces, if not placed between double quotes. The following table gives a detailed list of how different transfer functions can be specified:

scalePal Syntax     Example(s)     Description
<float> 2.0
5
A single float value is interpreted as scale. The class bounds are calculated using the following formula:
class bound = index * <float>
<float_1>,offset=<float_2> 2.5,offset=3
5,offset=-7
Note: Syntax not defined/implemented yet. The class bounds are calculated using the following formula:
class bound = index * <float_1> + <float_2>
<float_1>,<float_2> 100,300
5%,95%
The class bounds are calculated by linear stretching the palette index domain (index min to index max) to the given reach (<float_1> to <float_2>). The same formula as above is applied (scale and offset are calculated internally).
<float_1>,...,<float_n> 100,200,300
5%,50%,95%
The palette index domain (index min to index max) is equally split into n-1 intervals which are then mapped to the given values (<float_1> to <float_n>). Using relative values it is easy to realize a histogram equlization (e.g. 5%,25%,50%,75%,95%). Note: linear stretching (see above) is just a special case of the multiple value case.
auto auto The class bounds are calculated by stretching the palette index domain (index min to index max) to the valid data range. The same formula as above is applied (scale and offset are calculated internally).
scalePal=auto is normally used together with palettes containing indices ranging from 0 to 100, allowing a percentage interpretation of the palette.

Relative values are useful to achieve appealing continuous/equidistant colorizations when the input data contain gross errors and the relevant extents are not know. When ever needed, the module internally calls Module Histo to translate the percentage values to absolute values which are then used to build up the palette lookup tables.

The resulting color lookup table is output as a scalable vector graphics (SVG) file (see parameter legend).

Nomally, opalsColorize processes the entire area and the entire value range of the input channels. As possible for most modules, you can subselect the data by defining a filter and/or a limit. The parameter filter is used with point clouds (ODMs), the parameter limit can be used with grid models. Please consider that the limit parameter is of type opals::GridLimit (rather than just four double values). See the parameter description for further details.

Parameters for controlling the output are described in the following section:

  • As mentioned above, for ODMs the computed color values are stored within the ODM in the Red, Green and Blue attribute per default. For directly creating a LAS-file (and keeping the ODM unchanged) specify oFormat las or set a corresponding output file (eg. output_rgb.las) using parameter outFile.
  • For grid files one can specify any GDAL supported oFormat and/or a corresponding outFile. The result file usually has the same grid width as the input file. However, the parameter pixelSize can be used to specify a different grid width for the result. In this case the parameter resampling controls the (internal) interpolation for the new values before they are classified and colored.

Parameter description

-inFileinput ODM or grid model file
Type: opals::Vector<opals::OdmOrRasterFile>
Remarks: mandatory
Specifies the input ODMs or the grid model files.
OdmOrRasterFile: File path of an ODM or raster dataset.
See OPALS Datamanager and Supported grid/raster formats
-outFilecolorized output file
Type: opals::Path
Remarks: estimable
Color coded point cloud file (ODM or LAS) or raster map file name.
Estimation rule: In case of ODMs the color values are stored within the ODM, whereas for grid models the current directory and the name (body) of the input file are used as file name basis.
-oFormatoutput file format (e.g. ODM, LAS, GTiff, PNG, etc.)
Type: opals::String
Remarks: estimable
Output file format (point cloud file format or GDAL driver name). Supported formats: ODM, LAS, GeoTiff, JPEG, PNG, PNM, GIF, BMP, XPM...
Estimation rule: estimated from input file extension if not specified.
-attributeup to three attributes or bands to be used for colorizing
Type: opals::Vector<opals::String>
Remarks: default=z
Up to three attributes (ODM case) or raster bands (grid model case) can be used for colorizing. Whereas a given palette is used for the single attribute case, three attributes are translated to RGB considering the given attribute order. If one of the attributes is null (=invalid or no data value) the background color will be assigned.
-filtermodify the input using a (tree of) filter(s)
Type: opals::String
Remarks: optional
A filter string in EBNF syntax as described in section 'Filter syntax' can be passed to restrict the input data set (e.g. to consider last echoes only).
-limit2D clipping window
Type: opals::GridLimit
Remarks: optional
In case of ODMs input, the limit defines the processing regions ignoring the center and corner option, since it has no relevance.For the grid model input case, the output grid is created according to the given coordinates (left lower right upper). If no user defined limits are specified or -limit is even skipped, the OPALS Data Manager (ODM) extents are used. Rounding is enabled by default in case the limits are derived from the ODM and can be enforced for user defined limits (keyword: round).
GridLimit: Defines xy-limits for output grid/raster datasets. The limit coordinates specified by left/lower/right/upper either refer to pixel centers (default) or corners, and may optionally get rounded to multiples of the grid size.
Syntax: ['center'|'corner']['round']['(' left lower right upper ')']
-pixelSizepixel size of output raster image (grid model case only)
Type: float
Remarks: estimable
Edge length of one pixel in the resulting raster image.
Estimation rule: default value = model grid size.
-resamplingpixel resampling method (grid model case only)
Type: opals::ResamplingMethod
Remarks: optional
Possible values:  
  weightedAverage .... weighted average (low pass filter)
  simpleAverage ...... simple average (low pass filter)
  nearestNeighbour ... nearest neighbour
  bilinear ........... bi-linear interpolation
  bicubic ............ bi-cubic interpolation
  never .............. indicator avoiding resampling 
Method to be used for resampling the input grid to the specified pixelSize of the resulting raster image.
-palFilepalette file name
Type: opals::Path
Remarks: optional
The palette file contains the definition of a background color and a node-color-map.
-intervalclass width=equidistance interval [interval for legend annotations]
Type: opals::Vector<float>
Remarks: optional
Class width=equidistance interval. A second value can be specified, which will be used as interval for annotations.
-nClassesnumber of classes
Type: uint32
Remarks: optional
The (equidistant) class interval is calculated from 'nClasses' and value range of the 'attribute'. Ignored if 'interval' is specified.
-legendon / off / legend=legend file name
Type: opals::Vector<opals::ZColorLegend>
Remarks: default=on
A legend corresponding to the actually used palette will be written to the specified filename with format SVG.
-scalePalscaling factor for palette nodes [auto|scale factor|scale range]
Type: opals::Vector<opals::ScalePal>
Remarks: optional
If not specified, the min-max palette node range is stretched to the value range of the attribute.
If two values are specified (low high), the min-max palette node range is stretched to the given scale range.
-skipVoidAreasskip invalid/no data attributes
Type: bool
Remarks: default=0
If not specified, invalid attributes or no data values will be assigend with the background color.Otherwise, if the flag is activated, no color values will be assigned (in case of ODM) or transparent pixels set (in grid model case).

Palette File Format

A palette file is a simple XML file containing an element <OpalsPalette> which itself contain the following elements:

  • <name> Optional
  • <comment> Optional
  • <classes> This optional element has a mandatory attribute val containing the number of classes to be used by default (if neither parameter interval nor parameter nClasses will be specified).
  • <values> This element has a mandatory attribute type which value can be "RGB255" or "RGB".

and 3 to 256 elements

  • <entry> Each of these elements must have the following attributes:
    • val
      The value of this attribute may be "BG", "uf", or a number.
      • The value "BG" represents the background color which will be used for locations where no z value is available within the DTM.
      • The value "uf" represents the underflow value which will be used for z values smaller than zmin.
      • All other values have to be numeric values in ascending order and will be used for all z values equal to the value and smaller than the value of the next palette entry.
      • The palette entry with highest value will be used for all z values equal or higher than this value.
    • R red color component value
    • G green color component value
    • B blue color component value

and an optional attribute comment.

An image with indexed colors can contain no more than 256 colors. As we need a background color (BG) and one for values smaller than zmin (uf) and for values greater than zmax each, we can only have a maximum of 253 classes beetween zmin and zmax. If the number of classes specified by nClasses or calculated from other parameters is larger than 253 the resulting image will be a RGB-image.

Here is a simple example of a palette file:

<?xml version="1.0" encoding="ISO-885999" ?>
<?xml-stylesheet type="text/xsl" href="opalsPaletteStyle.xsl" ?>
<!-- Palette Definition for Opals -->
<OpalsPalette>
<name>Simple Example Palette</name>
<comment>For demonstration only.</comment>
<values type="RGB255" />
<entry val="BG" R="204" G="204" B="204" comment="background color" />
<entry val="uf" R="153" G=" 0" B=" 0" comment="underflow color" />
<entry val=" 0.000" R=" 0" G=" 68" B="144" comment="overflow color, index_max" />
</OpalsPalette>

The first two lines are only necessary to view the palette file with a WEB browser. The third line is a comment.

An OPALS distribution contains the following standard palettes:

  • standardPal.xml: used for terrain elevation codings (green land to brown mountains)

  • differencePal.xml: used for visualizations of (strip) differences (negative differences: blue, positive differences: red)

  • densityPal.xml: used for point density maps (poor density: red, yellow, satisfying density: green)

  • aspectPal.xml: terrain aspect

  • slopePal.xml: terrain slope

  • greyPal.xml: simple black-to-white palette for multiple purposes

  • Additional ColorBrewer palettes: ColorBrewer is providing cartographic color schemes

Implementation TODOs: 
- short examples for ODM case
- dual input channel case

Examples

The data used in the subsequent examples are located in the $OPALS_ROOT/demo/ directory and the follwing preprocessing steps (data import, surface grid and difference model calculation) are required:

opalsImport -inFile strip11.laz
opalsImport -inFile strip21.laz
opalsImport -inFile fullwave.fwf
opalsGrid -inFile strip11.odm -outFile strip11.tif -interpolation movingPlanes -gridSize 0.5
opalsGrid -inFile strip21.odm -outFile strip21.tif -interpolation movingPlanes -gridSize 0.5
opalsGrid -inFile fullwave.odm -outFile fullwave.tif -interpolation movingPlanes -filter Echo[last]
opalsDiff -inFile strip21.tif strip11.tif -outFile diff_11_21.tif
@ movingPlanes
moving (tilted) plane interpolation
@ last
last stage to be processed (opalsStripAdjust)
opalsDiff is the executable file of Module Diff
Definition: ModuleExecutables.hpp:58
opalsImport is the executable file of Module Import
Definition: ModuleExecutables.hpp:128
opalsGrid is the executable file of Module Grid
Definition: ModuleExecutables.hpp:103
@ filter
string to be parsed in construction of DM::IFilter (various modules)