MapInfo Pro

Raster Rendering Deep Dive – Part 5 – Fixed Data-Color Transforms

  • 1.  Raster Rendering Deep Dive – Part 5 – Fixed Data-Color Transforms

    Pitney Bowes
    Posted 12 days ago
    Edited by Sam Roberts 12 days ago

    The previous articles described default algorithms, LUTColor, RGBColor and Image layers. This article demonstrates how to use fixed "data to color" transforms in LUTColor layers and how to remap the colors in a classified raster.

    In all the examples we have looked at so far, the data – color transform has been created automatically from the statistics of the raster being rendered. For example, if we display a terrain raster using a "linear" transform then the colors in the color table are mapped linearly from the lowest data point in the raster to the highest. If we display a different terrain raster that has a different minimum and/or maximum cell value then we will get a different color mapping.

    What if we want a fixed mapping, where a data value in the raster maps to a specified color regardless of the raster statistics? This is called a fixed data – color transform. When we display rasters like this we may not get optimised color distributions but we will be able to make visual comparisons between different rasters that are displaying the same kind of data and using the same data – color transform. 

    This capability has been somewhat buried in MapInfo Pro Advanced - even in the latest release (17.04). You can achieve it by selecting the "User Defined" transform option in the "Advanced Color" dialog and creating a Breaks Table. You can load and save these tables and you can also save the rendering algorithm as a template which you can apply to other rasters. It is not particularly easy but the new rendering engine has some additional methods which we will now explore. 

    In the new rendering engine, fixed color-data transforms can be used in LUTColor and RGBColor layers and there are two ways to go about it. The first is to manually define the data transform in the algorithm and always use the same color table and the same transform in each layer or algorithm. The second is to use a color look-up table file which has a format that supports specification of both the colors and the data values within the same file - and to use this color file consistently in layers and algorithms. 

    The first technique is similar to the breaks table method used in MapInfo Pro Advanced, except that it has a range of additional capabilities. The simplest method is to define a Linear or Log transform and to specify the minimum and maximum range of the transform (bandpass values). There is a range of more advanced mappings that generally require you to specify a list of data values and the color index (between 0 and 1) that they map to. Below is the complete list. I don't plan to document these in this article, but feel free to express interest in the comments. 

    • NBitColor – A linear transform between 0 and 2^N-1.
    • Linear – A linear transform between the lower and upper band pass values.
    • Log – A logarithmic transform between the lower and upper band pass values.
    • UserLinearTable – Supply index over a set of bins equally spread over a data range.
    • UserNonLinearTable – Supply data values and index over a set of bins.
    • UserNonLinearPTGTable – Supply data percentage values and index over a set of bins.
    • UserNonLinearPTLTable – Supply data percentile values and index over a set of bins.
    • UserDiscreteValue – Supply a list of discrete data values and index.
    • UserDiscreteRange – Supply a list of data value ranges and index.
    • UserDiscreteString – Supply a list of string data values and index.


    The second technique is to use a color look-up table that supports the specification of both the colors and the data values within the same file. At present there are three formats that support this – the Vertical Mapper VCP format and two formats that were used in MapInfo Discover – the XLUT and LEG formats. All are simple ASCII files that you can create and edit in any text editor. 

    To use one of these files in an algorithm, connect the color file to both the color table definition and to the data transform definition. A simple example algorithm containing a LUTColor layer is shown below. You can use an algorithm like this as a template for displaying any raster using a LUTColor layer (pseudo-color equivalent). Here is the XML.
     

    <?xml version="1.0" encoding="UTF-8"?>
    <RenderAlgorithm Version="1.0" Enable="True">
    	<Raster Name="Raster01" File="Bathymmetry.ers"/>
    	<ColorTable Name="LUT01" Filename="elevation.vcp"/>
    	<DataTransform Name="Transform01" Filename="elevation.vcp"/>
    	<Layer Type="LUTColor" Enable="True">
    		<Component Type="Color" Enable="True">
    			<Raster Name="Raster01"/>
    			<ColorTable Name="LUT01"/>
    			<DataTransform Name="Transform01"/>
    		</Component>
    		<Component Type="Intensity" Enable="True">
    			<Raster Name="Raster01"/>
    		</Component>
    	</Layer>
    </RenderAlgorithm>
    


    In this example, I used a VCP file. Here is what the VCP file looks like.

    NWGS_VMCP_AA_BnArMy
    10
    	-10000		0	0	64	
    	-2500		0	0	255
    	-250		128	128	255
    	-1			192 192	255
    	0			160	160	160
    	250			0	128	0
    	1000		128	64	64
    	2500		0	64	0
    	4000		128	128	128
    	9000		255	255	255


    The first line has a strange string which you need to copy verbatim. The second line contains the number of color entries and the color entries follow – one per line. The data value is listed first followed by the Red, Green and Blue color components which are integer values ranging from 0 to 255. 

    This VCP can be used for elevation and covers a range of -10000 metres to 9000 metres with data below zero RL different shades of blue and data above zero RL shades of green, red and grey. Internally, the VCP information is turned into a table with 2048 colors. A UserNonLinearTable transform is created where the color specified in each row begins at the data value for that row. Between rows, colors are interpolated in RGB space. Below I have rendered a terrain and bathymetry raster of the Earth using this VCP. Note the sharp cut-off in color at 0 metres from blue (ocean) to grey (land). (I found a weakness in version 17.04 caused by this sharp transition, which is resolved in the upcoming Pro 2019 release). This global 60 arc-second resolution bathymetry and terrain raster has been rendered using this VCP transform and color table. I have not used hill-shading in this image.

    Fixed data - color transform rendering of the globe


    The XLUT format is very similar, with a few additional options and more precise control. You can specify how many colors are in the table and specify every color exactly if you wish. You can also interpolate between specified colors in either RGB or HSL space. Like VCP, a UserNonLinearTable transform is created where the color specified in each row begins at the data value for that row.

    LookupTable Begin
    	Interpolation = RGB
    	Scale = Byte
    	DataRange = PostColor
    	DataType = NumericContinuous
    	LUT = {
    		0		0	0	64	-10000
    		128		0	0	255	-2500
    		256		128	128	255	-250
    		384		192 192	255	-1
    		512		160	160	160	0
    		640		0	128	0	250
    		768		128	64	64	1000
    		896		0	64	0	2500
    		1024	128	128	128	4000
    		1280	255	255	255	9000
    	}
    LookupTable End
    


    Control color interpolation using the "Interpolation" tag and specify either "RGB" or "HSL". Control the color component data using the "Scale" tag and specify either "Byte" or "Word" where Byte ranges from 0 – 255 and Word ranges from 0 – 65535. If you have data values then use the "DataRange" tag and specify either "PreColor" to indicate they are listed before the color, or "PostColor" to indicate they are listed after the color. Also, use the "DataType" tag to indicate the data is either "NumericContinuous" or "NumericDiscrete" (it doesn't matter which) or "Text". The example below is equivalent to the VCP file shown earlier. Note the first number in each color item is the (zero based) color index and all colors in between the listed indices will be generated by interpolation. 

    The LEG format is used to define a legend which can contain other rendering styles like fill patterns, line styles and symbols but in the raster algorithm we just use the fill colors and ignore the rest of the information. We do not interpolate between specified colors, so a LEG file defines all the colors that will be used in the transform. The color values must be expressed as 32-bit integers so, if you know the 8-bit (0 – 255) color components, the formula for computing the color value is Red + Green*256 + Blue*65536. You can supply either a data value range, a unique data value or a data string for each color item. Use the "DataType" tag to specify either "NumericContinuous", "NumericDiscrete", "Numeric" or "Text". The LEG file below duplicates the VCP and XLUT tables defined earlier, but as there is no interpolation between the defined colors the rendering is quite different.

    LegendTable Begin
    	DataType = NumericContinuous
    	Leg = {
    		-10000	-2500	"Deep Ocean"		4194304		0	2	0	0	0	0
    		-2500	-250	"Ocean"				16711680	0	2	0	0	0	0
    		-250	-1		"Literal"			16744576	0	2	0	0	0	0
    		-1		0		"Shoreline"			16761024	0	2	0	0	0	0
    		0		250		"Low lying"			10526880	0	2	0	0	0	0
    		250		1000	"Low hills"			32768		0	2	0	0	0	0
    		1000	2500	"Low Mountains"		4210816		0	2	0	0	0	0
    		2500	4000	"High Mountains"	16384		0	2	0	0	0	0
    		4000	9000	"Mountain Peaks"	8421504		0	2	0	0	0	0
    		9000	10000	"Highest"			16777215	0	2	0	0	0	0
    	}
    LegendTable End

     

    A LEG file is useful when rendering classified rasters. Usually, classified rasters will have colors recorded in the class table and these are used to render the raster by default. If you want to override these colors then a LEG file can be used. For each item in the class table (which you can see in Pro via the Raster Info dialog) define a color item in a LEG file that uses the "Numeric" DataType. The data values used will simply be 0, 1, 2… up to the number of items in the class table (less one). Note that with a "Numeric" DtaaType you only need to specify a single data value per row, instead of two data values (representing "from" and "to").

    Please leave a comment if you are interested in exploring any of these topics further, or if you have any other queries about the raster rendering engine.



    ------------------------------
    Sam Roberts
    Engineer, MapInfo Pro Advanced (Raster)
    Australia
    ------------------------------

    Attachment(s)