-
Notifications
You must be signed in to change notification settings - Fork 37
Mosaic Operation
In this page will be described a modified implementation of the JAI Mosaic Operation that supports noData values and doesn't use threshold values. In this new Mosaic class the threshold is not used because it doesn't fit our requests.
NoData values are special values like -9999, Integer. MIN_VALUE , etc... which indicates the absence of informations in that pixel. There is no standard for these values so in every image there could be a different type of noData. In the old Mosaic operation behaviour, one way to avoid a single type of noData value was to set a specific threshold(equal to the noData value) and any value below it was considered a background value. If there were multiple images with multiple different noData values, the above behaviour could not be correct. For example, if there are 2 images with 2 different noData value types, the threshold could be set to the bigger value but, in this way, even the image pixel of the lowest noData value image that lays below the selected threshold are set to background value, unless are set two different threshold per image.
A simple way to avoid all of these inconvenients is to set an initial range of noData values to check when the Mosaic operation is performed. This multiple values are saved into an array of Range objects or in a singular Range objects, if they are contiguous. The new Mosaic operation should take this array of values and then use it for checking if there is noData values and handle them.
The classes composing this module are:
- MosaicOpImage.java
- ImageMosaicBean.java
- MosaicDescriptor.java
- MosaicRIF.java
- MosaicOPImage2.java
The MosaicOpImage.java class extends the OpImage abstract class and overrides its methods in order to perform the mosaic operation by taking into account the presence of ROI and No Data. Note that the final image dimension can be defined by setting an optional ImageLayout object inside the renderingHints or it is defined as the union of the image bounds.
The second class is a java Bean used for setting and getting all the image informations in one single object.
The third class is an extension of the OperationDescriptorImpl.java class containing the information about the MosaicOpImage, like the default values, class names and resources. The validateParameter() method is used for evaluating if the input parameter are correct for the operation. The isRenderable method informs that the image does not support the renderable mode.
The fourth class is an implementation of the RenderedImageFactory interface and is used for giving the possibility to create the mosaic RenderedImage by giving an input parameterBlock and calling the JAI.create method. This last operation requests that the Mosaic operation is registered to a new registryFile.jai (located into the META_INF directory) inside the project with a univoke name.
The last class is an older implementation of the MosaicOpImage that is not used because it has worst performance than that of the MosaicOpImage class.
A code example may be useful:
// MOSAIC TYPE OVERLAY
// s[i][x][y] = pixel value for the source i
// d[x][y] = pixel value of the destination
d[x][y] = destinationNoData;
for(int i=0; i< sources.length(); i++){
if(!SourceNoDataRange[i].contains(s[i][x][y]){
d[x][y] = s[i][x][y];
break;
}
}
// MOSAIC TYPE BLEND
// s[i][x][y] = pixel value for the source i
// w[i][x][y] = weigthed value of the destination
// d[x][y] = pixel value of the destination
w[i][x][y] = 0;
d[x][y]=0;
int numerator=0;
int denominator=0;
for(int i=0; i< sources.length(); i++){
if(!SourceNoDataRange[i].contains(s[i][x][y]){
w[i][x][y] = 1;
}
numerator+=w[i][x][y]*s[i][x][y];
denominator+=w[i][x][y];
}
d[x][y]=numerator/denominator;
//
There are 3 test classes:
- MosaicTestImage.java
- ComparisonTest.java
- MosaicTest.java
The first class calculates the mosaic operation on 2 image. This test-class allows the user to choose the new or the old version of the MosaicOpImage by setting in input to the JVM the JAI.Ext.NewDescriptor boolean parameter. For printing hte result to the screen the JAI.Ext.Interactive parameter must be set to true.
The second class compares the computation time between the 2 versions of the MosaicOpImage. The test cyclically takes an already existent image, gives it to the MosaicDescriptor (Old or New version) and call the PlanarImage.getTiles() method (in this way all the image tiles are calculated). The computation time is calculated only when the getTiles() method is called. At the end of the cycle the JAI TileCache is flushed, so that all the image tiles must be recalculated every time. The average, maximum and minimum computation times are not stored for all the iterations, because the first N iterations are not considered due to the Java HotSpot compilation. The number of the iteration to consider and not can be set by passing respectively these 2 Integer parameters to the JVM: JAI.Ext.BenchmarkCycles and JAI.Ext.NotBenchmarkCycles. If the descriptor to use is the old one, the user must set to true the JVM parameter JAI.Ext.OldDescriptor, otherwise the new descriptor is used. The mosaic type is by default OVERLAY, but if the JVM boolean parameter JAI.Ext.MosaicBlend is set to true, then the BLEND mosaic type is used. If the native acceleration should be used, then the JAI.Ext.Acceleration JVM parameter must be set to true. The statistics are print to the screen at the end of the process.
The last class executes many tests on the new MosaicOpImage class. These tests consist in a mosaic of 2 or 3 images with different kind of values. The Mosaic type used is OVERLAY.
For 2 images:
- image 1 with no data and image 2 with no data.
- image 1 with no data and image 2 with valid data.
- image 1 with valid data and image 2 with valid data.
- image 1 with no data and image 2 with ROI and valid data.
- image 1 with valid data and image 2 with ROI and valid data.
- image 1 with no data and image 2 with Alpha channel and valid data.
- image 1 with valid data and image 2 with Alpha channel and valid data.
For 3 images:
- image 1 with no data, image 2 with ROI and valid data, image3 with Alpha channel and valid data.
- image 1 with valid data, image 2 with valid data, image3 with valid data but no data Range selected.
This test are executed for images with 1 and 3 bands and for data type: Byte, Short, Ushort, Integer, Float, Double. For the BLEND Mosaic type some tests have been performed with 3 images: the first with no data, the second with a ROI and the third with an alpha channel. For every image some pixels are taken and their values are compared to the expected ones. Even the exceptions are tested.