Example: Import BIL and Combine 3 Bands

This topic provides a very technical example in which we import a BIL format file that produces three images, each using one band from the BIL.  We then create an image that uses the three bands for R, G and B.  BIL format fails to provide projection information, so for the sake of this topic we pretend the images are in default Pseudo-Mercator projection, as good as any other we might use.

Import a BIL file

il_import_bil01_03.png

 

Using the procedures described in the BIL, ESRI Band Interleaved by Line topic we import a BIL file called austin.bil.  

 

il_import_bil01_04.png

That results in a single table and three images, all three of which take their data from the same table.

 

il_import_bil01_06.png

 

Double-clicking one of the images open we see it shows a monochromatic display.  

 

il_import_bil01_06a.pngil_import_bil01_06b.png

 

Switching to the Components panel of the Contents pane, we see the default Pseudo-Mercator projection shown in red color, indicating it is a placeholder for an coordinate system that is unknown, since none was specified by the BIL file.  

 

The austin.bil file did not have a .prj associated with it and thus was not imported with a coordinate system assigned.  When we intend to work with this data in a spatial context we will need to launch Assign Initial Coordinate System to specify the correct initial projection for the imported imagery.  Since we do not know the correct projection, but we do not want to be annoyed by the red color throughout this topic, so for the time being we will simply assign the default.

 

btn_coord_sys_picker.png We click on the coordinate picker button and assign the initial coordinate system as the default Pseudo-Mercator projection.    We open the other two images in turn, and assign Pseudo-Mercator projection to them as well.  This is a fake assignment that will have to be changed to whatever is the correct coordinate system should we ever want to use this image in a real GIS project.

 

The three monochrome, mostly black, images do not convey useful information in a user-friendly way.  We can fix that with a bit of work.

 

il_import_bil01_05.png

 

Opening the table we see it contains three tile fields, all of which are single-channel fields using an int8 data type value per pixel.   This is a classic situation for multiband data stored in a BIL file.    To visualize the data we will have to create an image that combines data from the three int8 tile fields into a single, computed tile field that stores an int8x3 data type for each pixel, that is, a triplet of values.   We can then use each component of the triplet as a channel in an RGB or BGR image.

Create a New Tile Field

With the focus on the table, we choose Edit - Schema to launch the Schema dialog.   

 

il_import_bil01_07.png

 

The Schema dialog shows us that the three different tile fields each have had a spatial index built upon them.  Manifold uses a standard naming scheme by default, where the name of a tile field's index will be the name of the tile with an _x appended, and the names of the X and Y fields for the index prefixed.  

 

We will now add a new, computed field.

 

il_import_bil01_08.png

 

btn_schema_add.png Press the Add command button and then choose Field in the drop down menu.

 

il_import_bil01_09.png

 

In the Field dialog we enter the name TileAll and choose data type tile.  For pixels type, we choose int8x3, and we leave the size of the tile at 128 x 128 since that is the size of the other tiles in the table.    We want to make this a computed field, so we press Edit Expression to launch the Expression dialog.

 

il_import_bil01_10.png

 

In the Expression dialog we enter the expression:

 

TileChannelsConcat([Tile1],

TileChannelsConcat([Tile2], [Tile3]))

 

This expression builds a value for each int8x3 triplet by starting with the value from the Tile3 column and concatenating onto that the value from the Tile2 column,  which results in a ([Tile3], [Tile2]) doublet, and then in turn concatenating onto that the value from the Tile1 column, resulting in a ([Tile3], [Tile2], [Tile1]) triplet.   We press OK.

 

il_import_bil01_11.png

 

Back in the Field dialog we check our work and press OK.

 

il_import_bil01_12.png

 

The new, computed field appears in provisional, bluish color in the schema.  It has not yet been added to the table, but will be when we press the Save Changes button.

 

We will not do that quite yet, as we want to add a spatial index on the new field.

Add a Spatial Index

Manifold uses spatial indexes on tile fields to enable faster fetch and display of tile data in images.  When we import from typical image formats, both the tile field and the spatial index for the tile field normally will be created automatically by Manifold in the table.   When we manually create a new tile field in a table, we should create a spatial index on that tile field as well.  This is easy to do.

 

il_import_bil01_13.png

 

btn_schema_add.png Press the Add command button and then choose Field in the drop down menu.

 

il_import_bil01_14.png

 

In the Index dialog we provide a name for the new index, using the usual naming pattern recommended for indexes.  We could name the index whatever we want, but it makes sense to use a name that a literate Manifold user will immediately recognize as the name of an index on a tile.  X_Y_TileAll_x is more recognizable than naming the index Ringo or Josephine.

 

We choose spatial index for tiles (rtree) as the type, the X and Y fields, the TileAll tile as the Tile, and we leave the other entries as loaded by the dialog by default.   Press OK.  

 

il_import_bil01_15.png

 

There, that was easy!  The new index appears in provisional, bluish color in the schema.   To apply the changes we have made to the table, we press Save Changes.

 

il_import_bil01_16.png

 

Immediately, the new tile field appears in the table.   The table reports it uses int8x3, a triplet of int8 numbers, as the pixel type in the tiles.  The new TileAll column appears in read-only gray background because it is the result of a computed field.  The column values cannot be edited directly by us, because they are computed automatically by the system.

Create a New Image

Now that we have created a new, computed tile field in the table, our final step is to create an image that displays those tiles.

 

il_import_bil01_17.png

 

Before we do, we right_click on one of the existing three images and choose Properties so we can see the size of the image given in the Rect property.   We need that information to ensure that the new image we create matches the dimensions of the other images.   In the dialog above we see that the bounds are [ 0, 0, 1679, 1903 ].  We right-click that cell and choose Copy to copy those bounds, for later use.

 

In the Project pane we right-click on the austin Tiles table and we choose Create - New Image.

 

il_import_bil01_18.png

 

In the New Image dialog we use the default Name of austin Tiles Image..  We choose the TileAll field for the Tile, leaving the other values as set by the dialog by default.  In the Bounds box we Paste the bounds value previously copied,  so the size of [ 0, 0, 1679, 1903 ] is used.  We pause for a moment to curse the inconvenience of having to do so manually, and make a mental note to send in a Suggestion recommending this be done automatically.   We leave the coordinate system as is, and then we press Create Image.

 

A new image called austin Tile Image appears in the Project pane.

 

il_import_bil01_19.png

 

icon_message_red.pngWhen we double-click open the austin Tiles Image we first see a blank window with a red message icon in the tab.   Clicking View - Messages we see an invitation to build intermediate levels.    That only needs to be done once for a new image, so we click the button to do that and the image opens.   We see it is a gray scale photographic image.  

 

il_import_bil01_20.png

 

We zoom into the image to see it shows an aerial photo of the Austin, Texas, region.  

 

If we click open the Style dialog (not illustrated) we see that it is a BGR image where the three channels, one from each of the tile fields in the original table, are combined to produce a gray scale image.   This is an unusual arrangement for photography but something one runs into with BIL files that might have imaged a region using different frequencies, such as infrared, in different bands.

See Also

Contents - Transform

 

Assign Initial Coordinate System

 

BIL, ESRI Band Interleaved by Line

 

Style: Images