TNTmips

HOME

FREE PRODUCTS
  TNTlite
  TNTatlas
  TNTsim3D

DOWNLOADS
  Release Version
  Development Version
  FTP
  Language Kits
  Sample Geodata
  Reseller Resources
  Promotional

DOCUMENTATION
  Tutorials
  Technical Guides
  Quick Guides

SITE MAP


PipelineContrastCompositeToTIFF.sml


# PipelineContrastCompositeToTIFF.sml

# Sample standalone script to demonstrate an image pipeline application:
# applying contrast to three grayscale RVC source rasters and making an RGB composite GeoTIFF file.

# If any input grayscale raster does not have a contrast table, the script computes a standard
# contrast table for a temporary copy of this raster, then applies this contrast.

# 21 December 2007

# Requires Version 2007:73 or later of the TNT products.

numeric err;										# error value

# error checking procedure
proc ReportError(numeric linenum, numeric err) {
	printf("FAILED -line: %d, error: %d\n", linenum - 1, err);
	PopupError(err); 
	}

# procedure to compute standard contrast table for copy of input raster that has no contrast table
proc computeCon(class CONTRAST con, class RVC_RASTER Rast) {
	class RVC_OBJECT tempFile;
	class RVC_RASTER tempRast;

	# copy source raster to temporary file, then close source raster
	tempFile.MakeTempFile(1);
	Rast.CopyTo(tempFile, tempRast);
	Rast.Close();

	# open temporary raster and compute standard contrast table for it
	tempRast.OpenAttached("Write");
	con.ComputeStandard(tempRast, "normalize");
	Rast = tempRast;			# reassign temporary raster to original raster variable
	tempRast.Close();			# close temporary raster
	}

################################################################################
#################################  Main program  ###############################
clear();

# set context so script does not exit on error, allowing manual
# handling of errors (primarily used with CONTRAST class method
# to read a contrast table, which returns an error if no table exists).
_context.AbortOnError = 0;


# CHOOSE INPUT RASTERS
class RVC_RASTER Red, Green, Blue;			# input rasters to composite
class CONTRAST conRed, conGreen, conBlue;	# contrast class instance for each input raster
GetInputRaster(Red);

# check to ensure that first raster selected is a grayscale raster
if (Red.$Info.Type == "binary" or
	Red.$Info.Type == "16-bit color RGB" or
	Red.$Info.Type == "16-bit color BGR" or
	Red.$Info.Type == "24-bit color RGB" or
	Red.$Info.Type == "24-bit color BGR") 
	{
	print("Binary and composite rasters cannot be used as input for this script.  Exiting now.");
	Exit();
	}

err = conRed.Read(Red);							# read last-used contrast table into CONTRAST class
if ( err < 0) computeCon(conRed, Red);		# if none, call procedure to auto-contrast a copy of the raster

# get remaining input rasters, constrained to be the same type as Red 
GetInputRaster(Green, Red.$Info.NumLins, Red.$Info.NumCols, Red.$Info.Type);
err = conGreen.Read(Green);
if ( err < 0) computeCon(conGreen, Green);

GetInputRaster(Blue, Red.$Info.NumLins, Red.$Info.NumCols, Red.$Info.Type);
err = conBlue.Read(Blue);
if ( err < 0) computeCon(conBlue, Blue);

# Get filename and filepath for output TIFF file
print("Getting output file name.");
class STRING outFileName$ = GetOutputFileName("image", "Choose destination and name for output GeoTIFF file", ".tif");
class FILEPATH outFilePath(outFileName$);
printf("Output file path = %s\n", outFilePath);


# PIPELINE SOURCES: one for each color component
class IMAGE_PIPELINE_SOURCE_RVC source_Red(Red.GetObjItem() );
err = source_Red.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Set red source.");

class IMAGE_PIPELINE_SOURCE_RVC source_Green(Green.GetObjItem() );
err = source_Green.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Set green source.");

class IMAGE_PIPELINE_SOURCE_RVC source_Blue(Blue.GetObjItem() );
err = source_Blue.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Set blue source.");


# PIPELINE FILTERS to apply lookup table (from contrast) to sources
# red component
class IMAGE_PIPELINE_FILTER_LOOKUP lookupRed (source_Red);
err = lookupRed.SetContrastParm(conRed);		# set CONTRAST class instance as lookup table
if ( err < 0) ReportError(_context.CurrentLineNum, err);

err = lookupRed.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Initialized red contrast");

# green component
class IMAGE_PIPELINE_FILTER_LOOKUP lookupGreen (source_Green);
err = lookupGreen.SetContrastParm(conGreen);
if ( err < 0) ReportError(_context.CurrentLineNum, err);

err = lookupGreen.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Initialized green contrast");

# blue component
class IMAGE_PIPELINE_FILTER_LOOKUP lookupBlue (source_Blue);
err = lookupBlue.SetContrastParm(conBlue);
if ( err < 0) ReportError(_context.CurrentLineNum, err);

err = lookupBlue.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Initialized blue contrast");


# PIPELINE FILTER to make composite
# filter can accommodate different numbers of components, so it takes a STAGE_ARRAY of input stages
# (sources or previous filters; in this case, previous FILTER_LOOKUP stages
class IMAGE_PIPELINE_STAGE_ARRAY stages(lookupRed, lookupGreen, lookupBlue);
class IMAGE_PIPELINE_FILTER_COMPOSITE filter_comp(stages, "RGB");
err = filter_comp.Initialize();
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("Composite filter initialized.");


# PIPELINE TARGET
class IMAGE_PIPELINE_TARGET_TIFF target_comp_tif(filter_comp, outFilePath);
err = target_comp_tif.Initialize(); 
if ( err < 0) 
	ReportError(_context.CurrentLineNum, err);
else
	print("TIFF file initialized");


# EXECUTE the pipeline process
target_comp_tif.Process();

print("Done.");




Back Home ©MicroImages, Inc. 2008 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

15 August 2008

page update: 24 Dec 07