home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


AutoRegisterSPOT4bandWebTilesetRef.sml


# AutoRegisterSPOT4bandWebTilesetRef.sml

# Demonstrates use of the IMAGE_PIPELINE_AUTOREGISTER
# class to automatically generate control points for
# an input image from a reference web tileset on the internet.

# The input image is 4-band SPOT stored as separate
# raster bands in a TNT Project File where
# Band 1 = Near-Infrared
# Band 2 = Red
# Band 3 = Green
# Band 4 = Mid-Infrared

# The Image can have its original nominal georeference, which is 
# automatically converted to control points by auto-register.

# The reference image is assumed to be a 24-bit RGB color-composite
# (natural color) stored as a web tileset on the internet.

# Band 3 of the SPOT (green) is matched to the "Green" component
# of the RGB composite reference image for auto-register.  The
# resulting georeference is saved to all input image bands.

# Includes status dialog that shows an auto-register progress bar.

# 18 March 2011
# requires TNTmips 2011, 9-Feb-2011 update or later.
# Randy Smith, MicroImages Inc.

numeric err;

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

clear();  # clear the console

# choose image bands to auto-register
class STRING prompt$;
prompt$ = "Choose 4 SPOT MS bands:";
class RVC_OBJITEM inpObjItemList[];		# hash of RVC_OBJITEMs for selected raster objects
numeric numBands;

DlgGetObjects(prompt$, "Raster", inpObjItemList, "ExistingOnly");

numeric i;		# check ObjItem hash
for i = 1 to inpObjItemList.GetNumItems()
	{
	printf("Band %d = %s\n", i, inpObjItemList[i].GetObjectPath() );
	} 


# get URL for the web tileset to use for the reference
class STRING url$, default$;
default$ = "http://www.microimages.com/geodata/kappa/SD2010 GM state/SD2010 GM state.tsd";
prompt$ = "Enter or paste URL of web tileset reference:";
url$ = PopupString(prompt$, default$, "Web Tileset URL");


##########################################################
### Create status dialog and its context
##########################################################
class STATUSDIALOG statusD;		# status dialog to show process status
statusD.Create();
class STATUSCONTEXT statusC;		# context for the status dialog
statusC = statusD.CreateContext();


# create pipeline source for the single band of the input to use
# for Auto-Register; specify by 1-based index to the ObjItemList where 3 = Band 3 = green:
class IMAGE_PIPELINE_SOURCE_RVC inpSource(inpObjItemList[3]);
err = inpSource.Initialize();
if (err < 0) then ReportError(_context.CurrentLineNum, err);
else print("input source initialized");


# create pipeline source for the reference web tileset
class IMAGE_PIPELINE_SOURCE_TILESET refTileset(url$);
err = refTileset.Initialize();
if (err < 0) then ReportError(_context.CurrentLineNum, err);
else print("reference source initialized");

# filter to select the green component of the reference tileset
array numeric srcSamples[1];
srcSamples[1] = 2;  # index for green component 
class IMAGE_PIPELINE_FILTER_SELECT refTilesetGreen(refTileset, srcSamples, 1);
err = refTilesetGreen.Initialize();
if (err < 0) then ReportError(_context.CurrentLineNum, err);
else print("select filter for reference tileset initialized");


# set auto-register class parameters; CRS will be set automatically
# from the input image
print("Setting up auto-register...");
statusC.Message = "Setting up auto-register...";
class IMAGE_PIPELINE_AUTOREGISTER autoReg;
autoReg.SetAutoGenerateGCPs(1);		# set to auto-generate control points
autoReg.SetModel("PlaneProjective");	# set maximum model
autoReg.SetUseExistingGCPs(0, 0);	# use but don't adjust existing points (will be disabled when done)
autoReg.SetInitialAccuracy(20);		# 20 cells
autoReg.SetGCPSpacing(75);				# 75 cells
autoReg.SetMaxGCPResidual(2);			# 2 cells
autoReg.SetCorrPatchSize(128);		# 128 cells
autoReg.SetMaxModel("PolynomialOrder2");

# run auto-register
print("Parameters set, starting auto-register");
statusC.Message = "Running auto-register...";
autoReg.Run(inpSource, refTilesetGreen);

# get RMS XY residual and result model from the auto-register class
numeric resultRMS;
class STRING resultModel;
resultRMS = autoReg.GetResultRMSResidual();
resultModel = autoReg.GetResultModel();
printf("Result residual = %.2f\n", resultRMS);
printf("Result model = %s\n", resultModel);


# check the overall control point RMS and if it passes, save georeference to all
# of the inputs
if (resultRMS <= 1.5) 
	{
	print("residual less than cut-off, saving result");

	for i = 1 to inpObjItemList.GetNumItems()
		{
		autoReg.SaveGeoreference(inpObjItemList[i]);
		printf("saved georeference for input %d\n", i);
		}
	}

# set final status dialog message and destroy the dialog.
statusC.Message = "Script Ran to Completion";
statusD.Destroy();

print("Done");







Back Home ©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

25 March 2009

page update: 26 May 11