ImageStatsForCategoryRast.sml

  Download

More scripts: Raster

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# Compute Image Statistics by Category Raster
# Assumption: Source raster(s) and category raster must match.
# Requires TNT 2015 v. 2014_08_27 or later.
class RVC_RASTER ClassRast;	# category raster
class RVC_OBJITEM classObjItem;
class RVC_RASTER R1, R2, R3; # rasters from which to compute image statistics
class RVC_OBJITEM sourceObjItemList[];		# declare hash of ObjItems for source rasters
# Select the category raster and open for writing
DlgGetObject("Select category raster:", "Raster", classObjItem, "ExistingOnly");
ClassRast.Open(classObjItem, "Write");
# Select three rasters as sources of statistics
numeric minObjs = 1;  
numeric maxObjs = 3;
DlgGetObjects("Choose three rasters for statistics:", "Raster", sourceObjItemList, "ExistingOnly", minObjs, maxObjs);
# Open the three source rasters using the hash of ObjItems (for reading only)
R1.Open(sourceObjItemList[1], "Read");
R2.Open(sourceObjItemList[2], "Read");
R3.Open(sourceObjItemList[3], "Read");
if (R1.$Info.NumLins <> ClassRast.$Info.NumLins ||
	R2.$Info.NumLins <> ClassRast.$Info.NumLins ||
	R3.$Info.NumLins <> ClassRast.$Info.NumLins ||
	R1.$Info.NumCols <> ClassRast.$Info.NumCols ||
	R2.$Info.NumCols <> ClassRast.$Info.NumCols ||
	R3.$Info.NumCols <> ClassRast.$Info.NumCols )
	{
	PopupMessage("One or more of the source rasters does not match the category raster dimensions. \nExiting now.");
	Exit();
	}
# Compute selected image statistics: Mean and Standard Deviation.
# If "stats" string is not used, the function computes all statistics except Histogram Table. 
# The second raster parameter is the first source image; additional source images can be specified after the "stats" string
ComputeImageStatsByCategory(ClassRast, R1, "StatsByScript", "Image Stats from Script", "Mean, StdDev", R2, R3);