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



With the focus on the table, we choose Edit - Schema to launch the Schema dialog.   We click on the <new field> item, enter the name TileAll and choose data type tile.  Press Add and then OK.    A new field called TileAll appears in the table.





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.


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 in the Contents pane to specify the correct initial projection for the imported imagery.


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 panel's Expression tab to do the same in a simpler way.




With the austin Tiles table open we launch the Transform panel.  In the Transform panel we choose the TileAll field as the target 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 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.   That is a manual step that allows user specification of   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 Create - 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.




icon_message_red.pngWhen we double-click open the resulting 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 a temporary index.  We click the button to do that, the image opens and then we see it is a gray scale photographic image.  




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