﻿ Example: Transform Elevation Image to Flatten Bathymetry to Zero

# Example: Transform Elevation Image to Flatten Bathymetry to Zero

Using the Transform pane 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 pane  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.

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

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.

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:

• First, in images Manifold by default will not preview what a Transform operation does if the image is very large and involves many intermediate levels and thus the view which requires a preview could involve a really huge amount of data.  When working with really big data it is perfectly possible to command Manifold to take on really huge operations that will take hours to preview.   By zooming in we reduce the amount of data displayed to where a  preview is so quick it is reasonable to show by default.  That allows us to see what our proposed Transform will do to the data before we tell Manifold to yes, go ahead and do that.

• Second, by selecting a region we can optionally use the Restrict to selection option box in the Transform pane to confine the effects of the proposed Transform, and thus the preview, to only the selected region.    That allows us to compare what the proposed transform is doing to unmodified data by seeing the preview in part of the display while adjacent is the rest of the display that is unmodified.  A visual comparison like that is a great way to check what we are asking Manifold to do is what we really intend.

We launch the  Transform pane.

The pane launches with the Tile field for the image already the Target by default.   We click the Expression tab.

We check the Restrict to selection box.

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.

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.

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

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

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

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

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.

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 pane.   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.

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]

) 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:

Selection

Images

Command Window

Style

Style: Images

Style: Palettes

Transform Pane

Transform Templates - Images

SQL Operators

Example: Rearrange Channels using an Expression - We use a simple expression in the Transform pane to rearrange the order of channels within the data.

Example: Zoom In to See Transform Previews for Big Images - A short example showing how previews for the Transform pane 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 pane to modify an image.

Intermediate Levels