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


AutoRegisterSPOT4band.sml


# AutoRegisterSPOT4band.sml

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

# 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.

# 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.

# The CRS for georeferencing is read from the reference image
# and set in the auto-register class.  This section can be
# altered to retain the CRS of the input image or to set any
# other CRS for the image georeference.

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

# 16 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 ObjItem for the single natural-color reference raster (composite)
class RVC_OBJITEM refObjItem;
prompt$ = "Choose the composite raster for Auto-Register to reference:";
DlgGetObject(prompt$, "Raster", refObjItem, "ExistingOnly"); 


##########################################################
### 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 green component of the reference color-composite
class IMAGE_PIPELINE_SOURCE_RVC refSource(refObjItem, "Green");
err = refSource.Initialize();
if (err < 0) then ReportError(_context.CurrentLineNum, err);
else print("reference source initialized");

# get georeference for reference image to set CRS for auto-register
class IMAGE_PIPELINE_GEOREFERENCE refGeoref;
refGeoref = refSource.GetGeoreference();
printf("reference image CRS = %s\n", refGeoref.GetCRS().Name);

# set auto-register class parameters
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.SetCRS(refGeoref.GetCRS() );	# set CRS from reference image
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, refSource);

# 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