A request was submitted to Support asking for a way in ERDAS IMAGINE to ignore a range of values when calculating image statistics. When using ImageInfo (View/Edit Image Metadata) or the Image Commands tool (Edit Image Metadata) you can identify a single value to be ignored. This is usually 0, but it could be any value representing the "background" value of the image.
However there are cases when more than a single value should be ignored. One of the most common cases is with imagery that has been compressed using a lossy compression technique and a software package (or format) which does not maintain a NoData (or opacity) mask separate from the data bands themselves. When imagery is lossilly compressed, background areas that were originally all 0s might become a mixture of 0s, 1s, 2s, etc. In these cases it is beneficial for image display purposes to ignore several values in the statistics of the image.
Consequently this Spatial Model was put together to provide a "model snippet" showing how to use a Table to specify more than a single value to feed to the Ignore port of the Statistics operator. This can be embedded into a larger model to ensure that the output imagery has statistics created in the desired fashion.
This model was put together as a quick example of how you might use the technique. As provided, the expectation is that the user enters a value in the Less Than prompt which means that all DN values below that value will be excluded from the statistics calculation. In the example shown in the screenshot above, the Less Than value entered was 100. The input images did have pixels with DN values below this value, but interestingly it then had no pixels with DNs between 100 and 117, so the Minimum statistics value, having ignored all values less than 100, was 117.
The model works by dynamically constructing a Table with as many rows as the Less Than value, with values that start at 0 and increment by 1 in each subsequent row. I..e if I enter a Less Than value of 100, the model constructs a Table with 100 rows with values starting at 0 and going through to 99 on the last row. This Table is fed to the Ignore port of the Statistics operator so that all hundred values are ignored in the image statistics that are created.
By feeding the Raster stream through the Statistics operator itself and using the Raster Out port to then directly feed the Raster Output operator, the statistics created in the Statistics Operator are written directly into the header of the output image file (rather than the statistics being calculated on the output file as the normal post-processing step of raster file creation). If you embed this technique into a larger model remember to retain this positioning and linkage of the Statistics operator and the Raster Output to which you wish to associate the statistics.
It is also very easy to modify the model to cater to different "ignore" needs. Need to ignore all values greater than or equal to a specific value? Just change the Dynamic Table Input (Series) operator so that the Initial Value is the greater than value. Need to ignore discrete values (0, 5, 11, etc)? Replace the Dynamic Table Input (Series) operator with a Custom Table Input operator and define it to contain those values. Using Signed Integer data? Adjust the Initial Value appropriately. Etc.
One limitation of this model is that it relies on there being an output image file being created. In ERDAS IMAGINE 2016 v16.1 (or earlier) you cannot perform this task on an existing image file. However in ERDAS IMAGINE 2017 there will be an Update Statistics operator (or similar) which will enable this technique to be applied to existing image files.
Input Image: Name of the input image file for which new statistics will be generated. The default is for IMG format files, but the File Chooser can be used to select from many different raster formats.
Less Than: The value below which values will be ignored. This assumes unsigned integer values, so if the value entered is 3, the values 0, 1 and 2 will be ignored.
Output Image: Name of the new output image file with statistics.
|Run dialog for the pre-built model:|
Using new capabilites provided in ERDAS IMAGINE 2018 I've enhanced the model to update the original Input Image file, rather than needing to produce a new output file. This obviously saves time and disk space.