Skip to content

Clamp Operation

ebucchianeri edited this page Jan 30, 2016 · 1 revision

The Clamp operation takes one source image and sets all the pixels whose value is below a “low” value to that low value and all the pixels whose value is above a “high” value to that high value. The pixels whose value is between the “low” value and the “high” value are left unchanged.

WORKFLOW:

  • creation of the ClampOpImage class and related descriptor and RenderedImageFactory.
  • testing of the Clamp related classes.

The difference between this version of the Clamp operation and the JAI one is the possibility to handle No Data values and ROI.

The classes that compose this module are:

  • ClampOpImage.java: this class executes the Clamp operation.
  • ClampDescriptor.java: this class defines the parameters of the Clamp operation.
  • ClampCRIF.java: this class is a RenderedImageFactory for the Clamp operation.

The ClampOpImage class takes in input one source image and two array of double for low values and high values. These arrays can have one element used for all the bands of the source image or they can have the same number of elements that matches the number of bands of the source image.
The ClampDescriptor class defines the operation parameters and features. Also it provides a create() method which returns the final image. This method takes and groups the input parameters inside a parameterBlock object and call the RenderedImageFactory associated with the Clamp operation, ClampCRIF, passing the parameterBlock as parameter.
The ClampRIF class takes in input the parameters packed into a ParameterBlock object, unpacks them and then returns a new instance of the ClampOpImage with the defined parameters.

The test-class associated with this module is:

  • ClampTest.java

This class ensures that all pixel are calculated correctly. Each test is executed with and without NoData values and ROI. All the JAI data types are tested.

PSEUDO-CODE for Clamp operation:


// s[x][y][b] = pixel value of the source.
// d[x][y][b] = pixel value of the destination.
// validData = boolean indicating that the value is not a No Data.
// insideROI = boolan indicating that the pixel is inside the ROI.
// destinationNoData = value indicating destination No Data.
// lowval = array of low values.
// highval = array of high values.
// srcHeight,srcWidth,numBands = source image height, width and number of bands.

// 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 && insideROI){
if(s[x][y][b]< lowval[b]) {
d[x][y][b]=lowval[b];
} else if (s[x][y][b]> highval[b]) {
d[x][y][b]=highval[b];
} else {
d[x][y][b]=s[x][y][b];
}
}else{
d[x][y][b]=destinationNoData;
}
}
}
}