-
Notifications
You must be signed in to change notification settings - Fork 38
Border Operation
The "Border" operation adds the borders to an input image. The user can define the Padding for each image border.
WORKFLOW:
*creation of various JUnit test-file for evaluating the Border Operation. *development of a new BorderOpImage class to test with the previous test-file, the related Descriptor and RenderedImageFactory.
The classes that composes this module are:
- BorderOpImage.java : this class executes the Border operation defined by the user.
- BorderDescriptor.java : this class defines the parameters of the _Border_operation and returns a new instance of the BorderOpImage class.
- BorderRIF.java : this class is a RenderedImageFactory associated with the Border operation.
There are 4 possible way for filling the borders:
- filling with a constant value
- filling by copying the edge of the image repeatedly
- filling by reflecting the image values
- filling by wrapping the image; this means that the image border is equal to the value of the opposite side of the image.
The BorderOpImage class takes in input the padding dimensions on all the 4 image sides and an instance of the BorderExtender class. This object fills the image borders by calling its extend() method on each border tile. If No Data are present, then an optional No Data Range can be used for checking if each value is a No Data and then substituting it with the destinationNoData value defined by the user. The No Data control is executed both on the image tiles and on the image borders.
The BorderDescriptor class defines the operation parameters and features. Also it provides an utility method for calculating the Border operation. This method calls the RenderedImageFactory associated with the BorderOperation (BorderRIF).
The BorderRIF class takes in input the parameters packed into a ParameterBlock object, unpacks them and then returns a new instance of the BorderOpImage with the defined parameters.
A simple pseudo-code for better understanding the border operation:
// s[x][y] = pixel value of the source.
// d[x][y] = pixel value of the destination.
// validData = boolean indicating that the value is not a No Data.
// destinationNoData = value indicating destination No Data.
// borderTile = boolean indicating that the tile is on the image border.
// checkBorderNoData() = simple method for filling the No Data values with the destinationNoData value.
// numTiles,srcHeight,srcWidth = source image tiles number, height, width.
// Copying data into the inner tiles
for(int b = 0; b < numBands; b++){
for(int y = 0; y<srcHeight;y++){
for(int x = 0; x<srcWidth;x++){
if(validData){
d[x][y][b]=s[x][y][b];
}else{
d[x][y][b]=destinationNoData;
}
}
}
}
// Control on the borders
if(borderTile){
checkBorderNoData();
}
For checking the border operation these test-classes are used:
- BorderTest.java
- ComparisonTest.java
The first class tests if the borders are filled in the way defined by the border type. The tests are made for all the JAI allowed data types, for all the BorderExtender types, with and without No Data. For ensuring that the borders are correct, a border region of the image is taken and its values are checked.
The second test-class is used for evaluating the performances of this version of the border operator and the old JAI one. This test is made by executing the Border operation with one of the two BorderDescriptor 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 time 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 descriptor associated to the operation must be tested, the JAI.Ext.OldDescriptor JVM parameter must be set to true or false(true for the old descriptor and false for the new one); the JVM parameter JAI.Ext.TestSelector can be from 0 to 5 and indicates the image data type. The BorderExtender type can be choosen by typing a value from 0 to 3 to the JVM Integer parameter JAI.Ext.BorderType where:
- 0 indicates border filled with a 0 constant value.
- 1 indicates border filled with the edge of the image.
- 2 indicates border filled with the reflection of the image edge.
- 3 indicates border filled by wrapping the image with the opposite edge values.
Finally, if the user wants to add the NoData, the JAI.Ext.RangeUsed parameter must be set to true. The computation times are print to the screen at the end of the process.