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.  


The techniques shown in this topic are expert level and not an example of point-and-click user friendliness.  However, this topic is still useful for unveiling the inner mechanics of how images and tables and properties are related, as well as for showing how the general power of Manifold infrastructure can be applied to accomplish virtually any task.  Manifold is evolving rapidly, so the techniques shown in this example likely will  be supplanted by easier commands that require less manual manipulation.  

Import a BIL file



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



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




Double-clicking one of the images open we see it shows a monochromatic display.  The display does not immediately convey useful information.  We can fix that with a bit of work.




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 a 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 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 image.


Create a New Tile Field



We right-click on the * New Field column head in the table and create a new field called TileAll of data type tile.


We must now provide the characteristics of that tile field.   In current editions of Manifold this is a manual process as follows.




Right-click on the austin Tiles table and choose Properties.   In the Properties dialog, use the yellow *  icon three times to add three new fields (highlighted above to indicate the fields that were added): FieldTileType.TileAll with a value of int8x3, FieldTileSize.TileAll with a value of [ 128, 128 ] and FieldCoordSystem.TileAll with the same value for the coordinate system as the other three coordinate system properties, using copy and paste from one of the other properties to avoid keyboarding the long, JSON specification of coordinate system.   Note that all of these properties and values are stored within and exposed in the mfd_meta table.


It is not really critical to provide the coordinate system since the austin.bil file did not have a .prj associated with it and thus was not imported with the correct projection.  However, when at some future time we use the Initial Projection dialog to manually specify what projection this data is using the new tile field will be ready for it.


Populate the New Tile Field

So far we have just set up the infrastructure of a new tile field that will contain the combined data.   The heart of this example comes next, combining the data from the three original tile fields into the int8x3 combined field.   We can write an UPDATE query to do that in SQL, or we can take advantage of the Transform dialog's Expression tab to do the same in a simpler way.




In the austin Tiles table we right-click on the TileAll column head and choose Transform.  In the Transform dialog we choose the Copy template and then we click on the Expression tab to specify an expression, the value of which will be copied into the TileAll field.   We enter the expression:



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.




When we enter the expression the Transform dialog previews what will happen in blue preview color.   We press the Update Field button to apply the transform and to populate the TileAll field.   We now have a table with four fields that contain tile data.   Three of the tile fields have a single value for each pixel.  The fourth tile field, which we have just created and populated, contains a int8x3 triplet of values for each pixel.


Note that using the Transform dialog to populate the TileAll field is a hybrid of using a point-and-click dialog and using SQL.   The guts of the action was accomplished using an SQL function, but instead of writing an UPDATE query we used the Transform dialog's Copy template and the Expression pane to handle the updating of the table.


Create a New Image

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




Before we do, we will open the Info pane and then open one of the existing three images so we can see the size of the image.   We need that information to ensure that the new image we create matches the dimensions of the other images.   That is a manual step that no doubt will be eliminated as Manifold evolves in the weeks ahead with more user friendly dialogs for image creation.   In the dialog above we see that the bounds are [ 0, 0, 1679, 1903 ].


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




In the New Image dialog we use the default Name.  We choose the TileAll field for the Tile.  In the Bounds box we manually adjust the default bound 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, make a mental note to send in a Suggestion recommending this be done automatically, and then we press Create Image.




When we double-click open the resulting austin Tiles Image we first get a message.   Clicking View - Messages we see an invitation to build a temporary index.  We click the button to do that, the image opens and then we see it is a gray scale photographic image.  




After pausing for a moment to  make a mental note to send in a Suggestion recommending that the addition of any necessary index be a default part of the New image dialog, 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

Transform Dialog


BIL, ESRI Band Interleaved by Line