|Left: Input multi-band Landsat image, bands 4,3,2; Middle: Zone raster of land use classes; Right: Zonal Mean results, bands 4,3,2|
There are some Operators in the Spatial Modeler which only operate on a single band at a time, such as the Zonal [Function] operators. For example, a Zonal Mean operation takes the Zone input layer and, for the extent of each zone value, looks at a second dataset (the "Class" layer) and calculates the Mean of those pixels that fall within the Zone - but the Class can only be a single band. So if you wanted to calculate the Zonal Mean from a 4 band "Class" image, you would need to have four branches in the model, one for each Zonal operation. This is relatively straightforward, but hardwires your model to data with that fixed number of input bands. If you wanted to process a 5 band "Class" image you would have to physically edit the model to add a fifth Zonal branch.
However in ERDAS IMAGINE 2016 we introduced the Iterator operator. This enables a sub-model to be executed n times, the number n being controlled by the length of an input list.
So this model provides an example of handling input images with varying numbers of bands by iterating across the number of bands provided. In this instance calculating the Zonal Mean per Band. It doesn't matter how many bands the Input MS Image has, the Iterator will run as many times as necessary to handle all the input bands without the model needing to be modified.
The Raster Information operator provides three items of information necessary for the model's execution. Primary amongst these is the Bands Count form the Input MS Image. The number of bands is then used in the Dynamic Table Input (Series) operator to (dynamically) build a table with as many rows as there are bands and with each row representing a band number (for example if the Input MS Image had 6 bands a Table would be constructed consisting of the values 1,2,3,4,5,6). This Table is then what controls the Iterator sub-model.
|Iterator Sub-Model to calculate per-band Zonal Means|
The Iterator Sub-Model will be executed a number of times represented by the length of the input Table (6 times in our example). within this Iterator the Sub-Model takes the first entry in the Table (the value 1, representing Band 1) and uses it to form a Band Selection range list and the Zonal Mean executes on this band (as the Class input). The sub-model then re-iterates and the next time it takes the value 2 off the input Table and so calculates the Zonal Mean of Band 2. Etc. Once the iterations have completed the Stack Layers operator assembles the results into an n band image where each band represents the zonal mean values of each band from the Input MS Image.
The other two items taken from the Raster Information operator are the Data Type of the Input MS Image (e.g. Unsigned 16-bit) so that the Output Image of zonal mean values can be truncated to the same data type (alternatively you could modify the model to leave it as Float). The final piece of information is the Thematicity of the Input MS Image so that the Output Image can be set the same.
This is a simple model, intended to provide a basic example of how to use the Iterator to process a variable number of input bands. Please also refer to the article for a more complex example of using Iterator operators.
Input MS Image: The name of the input n band image, the bands of which will act as the "Class" raster in the Zonal Mean calculation
Input Zone Image: The name of the input thematic image whose classes will act as the Zone locations for the zonal Mean calculation. The image should be Thematic and have only a single band.
Output Image: The name of the output image file to be created. This image will have the same number of bands as Input MS Image (and the same data type and thematicity) with the bands representing the mean values for each Zone.