-
Notifications
You must be signed in to change notification settings - Fork 37
Rescale Operation
This new module implements a new version of the JAI Rescale operation with the addition of NoData and ROI support.
WORKFLOW:
- creation of the classes for performing the Rescale operation
- testing of the previously created classes.
The classes that compose this module are:
- RescaleOpImage.java : this class is the object which executes the rescale operation.
- RescaleDescriptor.java : this class contains the description of the operations and of the input parameters to pass to the RescaleOpImage class.
- RescaleCRIF.java : this class is a RenderedImageFactory used for creating a new instance of the RescaleOpImage class.
The RescaleOpImage class is used for doing the rescale operation. This one consists of mapping the pixel values of an image from one range to another range; the mapping is done by multiplying every pixel with a constant and then adding an offset. These parameters can vary between the bands. The rescale operation is executed for each tile separately so that multiple thread can work simultaneously on the same image without the risk of loosing thread-safety. If ROI or No Data Range are used, then every pixel which is outside the ROI or it is a No Data is substituted with the destination No Data value passed in input.
The RescaleDescriptor describes the rescale operation and its parameters. It provides an utility method for creating Rendered and Renderable images by calling respectively the create() and createRenderable() methods.
The RescaleCRIF class is the RenderedImageFactory associated to the rescale operation. It is called by the JAI.create() method and returns a new instance of the RescaleOpImage.
A simple pseudo-code for understanding the Rescale operation:
// d[x][y][b] = pixel value of the destination.
// s[x][y][b] = pixel value of the source.
// scales[] = scale factor array
// offsets[] = offsets array
// insideROI = boolean indicating that the pixel is inside ROI.
// validData = boolean indicating that the pixel is not a No Data.
// destinationNoData = value indicating destination No Data.
// numTiles,numBands,srcHeight,srcWidth = source image tiles number, bands number, height, width.
for(int t = 0; t<numTiles;t++){
for(int b = 0; b<numBands;b++){
for(int y = 0; y<srcHeight;y++){
for(int x = 0; x<srcWidth;x++){
if(insideROI && validData){
d[x][y][b]=s[x][y][b]*scales[b] + offsets[b];
}else{
d[x][y]=destinationNoData;
}
}
}
}
}
These test-classes are used for evaluating the functionality of the RescaleOperation:
- RescaleTest.java
- ComparisonTest.java
The first test-class is used for checking if this version of the Rescale operation behaves correctly. The comparison is made by taking the first tile of a rescaled image and ensuring that all its pixels are equal to the result of the multiplication of each source pixel with the same scale factor and the addition with the same offset factor. The optional presence of ROI and NoData is considered. The user can see the result of the rescaling in different cases by setting the JVM parameters JAI.Ext.Interactive to true and JAI.Ext.TestSelector to the associated value:
- 0 without ROI and NoData
- 1 with ROI RasterAccessor and without NoData
- 2 with ROI and without NoData
- 3 with ROI RasterAccessor and with NoData
- 4 without ROI and with NoData
- 5 with ROI and NoData
The second test is used for evaluating the performances of the new and the standard Rescale operators. This test is made by executing the rescale operation with one of the two RescaleDescriptor and saving the mean, maximum and minimum computation time. At the end of every cycle the JAI TileCache is flushed so that all the image tiles must be recalculated. The average, maximum and minimum computation times are not saved for all the iterations, because the first N iterations are not considered due to the Java HotSpot compilation. The number of the iterations to consider and not can be set by passing respectively these 2 Integer parameters to the JVM: JAI.Ext.BenchmarkCycles and JAI.Ext.NotBenchmarkCycles. For selecting which of the 2 operations must be tested, the JAI.Ext.OldDescriptor JVM parameter must be set to true or false(true for the standard descriptor and false for the new one); the JVM parameter JAI.Ext.TestSelector can be set from 0 to 5 and indicates the image data type. Finally, if the user wants to add the NoData or ROI control, the JAI.Ext.RangeUsed and the JAI.Ext.ROIUsed parameters must be respectively set to true. The computation times are print to the screen at the end of the process.