Skip to content

Threshold Operation

ebucchianeri edited this page Feb 3, 2016 · 1 revision

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

WORKFLOW:

  • creation of the ThresholdOpImage.java class and related descriptor and RenderedImageFactory.
  • testing of the Threshold related classes.

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

The classes that compose this module are:

  • ThresholdOpImage.java : this class executes the Threshold operation.
  • ThresholdDescriptor.java : this class defines the parameters of the Threshold operation.
  • ThresholdCRIF.java : this class is a RenderedImageFactory for the Threshold operation.

The ThresholdOpImage class takes in input one source image and three array of double, one for low values, one for high values and the last for the constant 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 ThresholdDescriptor 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 Threshold operation, ThresholdCRIF, passing the parameterBlock as parameter.

The ThresholdRIF class takes in input the parameters packed into a ParameterBlock object, unpacks them and then returns a new instance of the ThresholdOpImage with the defined parameters.

The test-classes associated with this module is:

  • ThresholdTest.java

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

PSEUDO-CODE for Threshold operation:


// s[x][y][b] = pixel value of the source image.
// d[x][y][b] = pixel value of the destination image.
// 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.
// constantval = array of constant 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] && s[x][y][b] =< highval[b] ) {
d[x][y][b]=constantval[b];
} else {
d[x][y][b]=s[x][y][b];
}
}else{
d[x][y][b]=destinationNoData;
}
}
}
}