RATIOSCL.sml

  Download

More scripts: Raster

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# RATIOSCL.sml 
# Sample script for tutorial "Writing Scripts with SML"
# Example of calculations and functions with raster objects.
# Compute ratio between two raster image bands and rescale
# to 8-bit unsigned range for output raster.
# Ratio = 1.00 is scaled to 128.  Separate scaling
# is applied for ratios less than or greater than 1.00.    
# Scale factor for upper range is based on global maximum
# ratio value, requiring creation of temporary ratio raster.  
# REVISED 21 September 2009
# Variable declarations
class RVC_RASTER N, D, Ratio, RatioScl;
class RVC_NULLMASK nullmask;
numeric rmax, scale, output;
clear();
GetInputRaster(N); 
# Check to make sure that second raster has same dimensions
GetInputRaster(D, N.$Info.NumLins, N.$Info.NumCols, N.$Info.Type);
GetOutputRaster(RatioScl, N.$Info.NumLins, N.$Info.NumCols, "8 bit unsigned");
nullmask.Make(RatioScl, 1);
#SetNull(RatioScl, 0);
CreateTempRaster(Ratio, N.$Info.NumLins, N.$Info.NumCols, "32-bit float");
for each N {  # compute ratio values for temp raster
	if ( !D == 0 ) then  # no division by zero
		Ratio = N / D;
}
rmax = GlobalMax(Ratio);  # get maximum ratio value
scale = 127 / (rmax - 1);	# compute scaling factor
									# for upper range
print("rmax =", rmax);
print("scale =", scale);
						# compute scaled values and
for each Ratio {	# write to output raster 			
	if ( Ratio < 1.00 ) then
		output = Ratio * 127 + 1;
	else
		output = 128 + (Ratio - 1) * scale;
	RatioScl = output;
}
CopySubobjects(N, RatioScl, "georef");
CreateHistogram(RatioScl);
CreatePyramid(RatioScl);
# End