|
TNTmips Downloads Menu

|
RATIOSCL.sml
# RATIOSCL.sml
# Sample script for tutorial "Writing Scripts with SML"
# 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.
# Variable declarations
class RASTER N, D, Ratio, RatioScl;
numeric numlins, numcols;
string type$;
GetInputRaster(N);
numlins = NumLins(N);
numcols = NumCols(N);
type$ = RastType(N);
numeric rmax, scale, output;
# Check to make sure that second raster has same dimensions
GetInputRaster(D,numlins,numcols,type$);
GetOutputRaster(RatioScl,numlins,numcols,"8 bit unsigned");
SetNull(RatioScl,0);
CreateTempRaster(Ratio,numlins,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
©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010 USA
Business & Sales: (402)477-9554 Support: (402)477-9562 Fax: (402)477-9559
Business info@microimages.com
Support support@microimages.com
Web webmaster@microimages.com
| |