Example: Transform Elevation Image to Flatten Bathymetry to Zero

Using the Transform panel with an image, which contains a single data channel for terrain elevation data for land together with bathymetry data for oceans, we use the Expression tab of the Transform panel  to reset all pixel values less than zero to zero.   This takes all below-zero elevations and sets them to zero, in effect removing bathymetry effects so that ocean areas are represented with zero elevation.  

 

The data set we will use is US government space shuttle SRTM data that was combined with bathymetry data to show terrain elevations as well as ocean depths.   The data uses sea level as the zero mark so terrain elevations are positive numbers while negative numbers represent depths.  The data imports into Manifold as an image that is made up of a single data channel.  SRTM data is published as rectangles that tile the Earth.   The particular data set we use shows a region centered approximately on the Red Sea.

 

eg_transfom_images_expr01_01.png

 

We open the image and use Style to color it with a palette as seen below.

 

eg_transfom_images_expr01_00.png

 

Scrolling up and down through the palette intervals list, we see the data ranges from -5868 to 5778.    For this particular example we would like to replace all the negative numbers, that is, all depths, with a value of 0, thus removing all relief below sea level.   

 

The task is a common one in spatial engineering and occurs for various reasons.   For example, we might need to use this data with a GIS or other package, such as a 3D modeling package,  that cannot work with negative numbers for terrain elevations.   Or we might be creating a data set for use in a modelling show that will use a 3D printer to create a tabletop model of the terrain but which requires ocean regions to be flat.   For whatever reason, our task is to replace all negative numbers, that is, depths, with a value of 0.

 

An experienced Manifold operator would just do that in a single step using a single expression.   Since this is a tutorial example we will do the job the way a beginner might approach the task, taking it in a few simple steps that allow checking the workflow along the way.     

 

eg_transfom_images_expr01_02.png

We begin by zooming in to a region right off the tip of the Horn of Africa, with the Gulf of Aden seen at the top and the Arabian Sea to the right and lower right.   We also draw a selection box with a Ctrl-click and drag to Select the tiles in the center of the view.     The rectangular region of the selected tiles is shown by a red selection border and translucent fill.

 

Why did we zoom in and why did we select some tiles?  There are two reasons:

 

 

 

In the Contents pane we click on the  Transform panel.

 

eg_transfom_images_expr01_03.png

 

The panel launches with the Tile field for the image already the Target by default.   We click the Expression tab and we check the Restrict to selection box.

 

eg_transfom_images_expr01_04.png

 

The expression we use is a trivial expression that uses a single Manifold SQL function for tiles,  TileMax.   If we forget the exact name of the function or we would like to construct the expression by double-clicking a sample in the query builder pane, we enter Tile into the filter box so that out of the zillions of operators and functions Manifold offers the pane only shows those with Tile in their names.   We scroll down to where TileMax is found, double-click it to enter the function into the expression pane without risk of keyboarding errors in the name of the function and then we fill it in to form the expression

 

 TileMax([Tile], 0)

 

The TileMax function takes two values and returns a pixel value that is the larger, that is, the maximum, of the two.   The expression says to take whatever is in the pixel value for the tile, compare it to 0 and use whichever is bigger.   For all negative pixel values obviously 0 will be the greater of the two.   For all pixel values over land which have an elevation value greater than zero, the value of whatever is already in the tile will be the larger, since any positive number is greater than 0, so all positive pixel values will be left unchanged.

 

Manifold shows a preview as soon as we write enough of an expression for it to be an executable expression.

 

eg_transfom_images_expr01_05.png

 

Since we checked the Restrict to Selection box the preview for what the expression does will be shown only within the selected region.  The preview is shown using blue preview color for the box border and a dotted fill that allows the preview within the box to be seen more clearly.

 

We can see that regions where elevation values were negative, that is, depths in ocean regions, have indeed been all set to the same value as shown by the palette color, the color assigned to 0 channel values.   At the same time, elevation values over land have not been changed.  That is expected since all the elevation values over land are greater than zero.

 

eg_transfom_images_expr01_06.png

 

Since we want to apply the transform to the entire image we will uncheck the Restrict to selection box.

 

eg_transfom_images_expr01_07.png

 

Right away the preview is now applied to the entire view and not just to the selected region.  

 

eg_transfom_images_expr01_08.png

 

To apply the transforming expression we press the Update Field button.

 

eg_transfom_images_expr01_09.png

 

Back in the image window we see the transform has been applied.   We also see the selection box again.

 

eg_transfom_images_expr01_10.png

 

We can get rid of the selection box by choosing Edit - Select None in the main menu, or by pressing Shift-Ctrl-A as a keyboard shortcut to deselect all.    With that we now have a clean display that shows all ocean areas with an elevation of 0, exactly as we expect of sea level.

 

eg_transfom_images_expr01_11.png

 

Zooming out to see the entire data set we see the transform has indeed been applied to all the data and has not modified any land regions, that is, all regions where elevations were already above zero.

 

Learning About Queries

In the above sequence we applied the transform expression to the image by pressing the Update Field button in the Transform panel.   As an alternative we could have pressed the Edit Query button to launch the Command Window with a query automatically generated by Manifold that executes the expression and updates the image.

 

eg_transfom_images_expr01_12.png

Doing so is a great way to learn SQL and how to utilize various functions.   The query generated is:

 

PRAGMA ('progress.percentnext' = '100');

UPDATE (

  SELECT [Y], [X],

    [Tile],

    CASTV ((TileMax([Tile], 0)) AS INT16) AS [n_Tile]

  FROM [e020n40.Bathymetry.srtm]

  THREADS SystemCpuCount()

) SET [Tile] = [n_Tile];

EXECUTE CALL TileUpdatePyramids([e020n40.Bathymetry.srtm]);

 

The PRAGMA and THREADS statements are routine housekeeping statements, with PRAGMA setting up the progress bar and THREADS the usual default of using all available CPU cores.  

 

 

Notes

Hill shading - We can apply shading if we like:

 

eg_transfom_images_expr01_13.png

 

 

See Also

Selection

 

Images

 

Command Window

 

Queries

 

Functions

 

Style

 

Style: Images

 

Style: Palettes

 

Transform Panel

 

Transform Templates - Images

 

SQL Operators

 

SQL Functions

 

Examples

 

Example: Zoom In to See Transform Previews for Big Images - A short example showing how previews for the Transform panel will appear in large images only when zoomed in far enough so computation of the preview does not cause objectionable delays.

 

Example: Parallel Speed Increase in an Image Transform - A short example illustrating how checking the Allow parallel execution option (on by default) increases speed by a factor of four in a simple use of the Transform panel to modify an image.

 

Intermediate Levels