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


LandsatCalibrationPilot.sml


# VB_PanSharp.xml

# Sample script that illustrates the use of a complex custom
# dialog window constructed using Visual Basic and registered
# as an ActiveX component class.  The Visual Basic
# class VBform is imported by the SML script, so its
# class members are available to SML, and callback
# procedures in the SML script can be bound to the relevant
# controls on the Visual Basic dialog.

# This is a Visual Basic version of the script pansharpcomp.sml.
# Both scripts compute a pan-sharpened color-composite 
# image from three bands of a multispectral image and a 
# higher-resolution panchromatic image.

# If the Apply Contrast option is selected for an input raster, 
# the last-used contrast table is used to make a contrast-adjusted
# temporary raster for further processing.  Perform necessary
# contrast enhancements for the input rasters and save contrast
# tables before running the script.

# This script requires TNTmips 7.3 or later on a computer running Windows98,
# Windows2000, or later Windows OS.

# The ActiveX component imported by this script can be downloaded from
# http://www.microimages.com/downloads/smlscripts.htm.  The ActiveX
# component must be registered first by running the Setup program in the
# Package subdirectory of the VB_PanSharp directory.  

# Jeremy Johnson
# MicroImages, Inc.
# 1 March 2004

# revised 4 January 2010.

##################################################################
###
###  use preprocessor command to "import" the Visual Basic ActiveX
###  component class VBform.  Note that preprocessor command lines
###  must NOT end in a semicolon (;).
###
##################################################################

$import VB_PanSharp.VBForm

###################################################################
########## Global Class Declarations ##############################
###################################################################

class VBForm form;

###################################################################
########## Global Variable Declarations ###########################
###################################################################

numeric ret;			# value returned by the class method that opens dialog

numeric numlinsP;		# number of lines in panchromatic raster
numeric numcolsP;		# number of columns in panchromatic raster
class STRING datatypeP$;	# data type of panchromatic raster

class RVC_RASTER RedCon, GreenCon, BlueCon, PanCon;		# temporary rasters for
																			# contrast-enhanced bands

class RVC_RASTER RedRsp, GreenRsp, BlueRsp;		# temporary rasters for resampled
																# RGB components

class STRING method$;		# color blending method from dialog listbox;

### variables for color conversion

class RVC_RASTER RedSharp, GreenSharp, BlueSharp;	# temporary rasters for pan-sharpened color components
numeric r, g, b, p;	# values of red, green, blue, and pan components for current cell
numeric h, i, s;		# values of hue, intensity, and saturation for current cell (from r, g, b)
numeric br;				# brightness value for current cell in HBS color model (from r, g, b)
numeric scale;			# scale factor for Brovey transform

### variables for color composite
numeric bdepth;				# desired bit depth of output composite from dialog: 24, 16, or 8
numeric depth;
string compdatatype$;		# string with datatype of composite raster
class RVC_RASTER Comp;		# output raster for color composite

numeric compobjnum;			# object number of output composite raster
class STRING compfilename$;		# filename, object name, and object descriptions
class STRING compobjname$;			# for output composite raster
class STRING compobjdescr$;

numeric conred, congreen, conblue, conpan; #for application of contrast options


##########################################
# procedure to select band and write its filename / object name
# to the dialog (in edittext field)
##########################################
proc GetBand(class RVC_RASTER Band, string id$) {

	local class STRING filename$, objname$, dlgtext$;
	local numeric objnum;

	GetInputRaster( Band, 0, 0, "8-bit unsigned" );
	filename$ = GetObjectFileName( Band );
	objnum = GetObjectNumber( Band );
	objname$ = GetObjectName( filename$, objnum );
	dlgtext$ = sprintf( "%s.%s /  %s", FileNameGetName(filename$), FileNameGetExt(filename$), objname$ );

	if (id$ == "rname") {
		form.RedName = dlgtext$;
	} else if (id$ == "gname") {
		form.GreenName = dlgtext$;
	} else if (id$ == "bname") {
		form.BlueName = dlgtext$;
	} else if (id$ == "pname") {
		form.PanName = dlgtext$;
	}
} 	# end proc GetBand()

###########################################
# callback procedure for the Red... pushbutton; prompts user to 
# select the Red color component
########################################### 
func SelectRed () {
	class RVC_RASTER Red;

	GetBand( Red, "rname" );
	form.RedSelected();
}	# end proc SelectRed()

###############################################
# callback procedure for the Green... pushbutton; prompts user to 
# select the Green color component 
###############################################
func SelectGreen () {
	class RVC_RASTER Green;

	GetBand( Green, "gname" );
	form.GreenSelected();
}	# end proc SelectGreen()

###############################################
# callback procedure for the Blue... pushbutton; prompts user to 
# select the Blue color component 
###############################################
func SelectBlue () {
	class RVC_RASTER Blue;

	GetBand( Blue, "bname" );
	form.BlueSelected();
}	# end proc SelectBlue()

################################################
# callback procedure for the Intensity... pushbutton; prompts user to 
# select the Intensity component
################################################ 
func SelectPan () {
	class RVC_RASTER Pan;

	GetBand( Pan, "pname" );
	form.PanSelected();
}	# end proc SelectPan()


##################################################
#Function to get the values stored in the form
###################################################
func GetValues() {
	depth = form.depth;
	conred = form.conred;
	congreen = form.congreen;
	conblue = form.conblue;
	conpan = form.conpan;
	method$ = form.method;
	form.CloseForm();
	}

#########################
# Bind form events to SML functions
#########################
form.SetOnbtnRed(SelectRed);
form.SetOnbtnBlue(SelectBlue);
form.SetOnbtnGreen(SelectGreen);
form.SetOnbtnPan(SelectPan);
form.SetOnbtnOK(GetValues);

##########################
# Display the Dialog (modal)
##########################
form.ShowDialog();


#################################################
### Get the output raster for the composite
#################################################
### Get setting for composite bit-depth
### Taken from the form's combobox
### an index value of 1 indicates 24-bit
### an index value of 2 indicates 16-bit
if ( depth == 1 ) {
	compdatatype$ = "24-bit color RGB";
	bdepth = 24;
} else { 
	compdatatype$ = "16-bit color RGB";
	bdepth = 16;
}

### Get the output raster
numlinsP = NumLins( Pan );
numcolsP = NumCols( Pan );

GetOutputRaster( Comp, numlinsP, numcolsP, compdatatype$ );


##############################################
### apply contrast tables if requested
##############################################

printf( "Applying contrast if requested...\n\n" );
datatypeP$ = RastType( Pan );

CreateTempRaster( RedCon, NumLins( Red ), NumCols( Red ), RastType( Red ) );
CreateTempRaster( GreenCon, NumLins( Green ), NumCols( Green ), RastType( Green ) );
CreateTempRaster( BlueCon, NumLins( Blue ), NumCols( Blue ), RastType( Blue ) );
CreateTempRaster( PanCon, numlinsP, numcolsP, datatypeP$ );

if (conred == 1 ) then
	RasterApplyContrast2( Red, RedCon, "Subobject" );
else {
	RedCon = Red;
	CopySubobjects(Red, RedCon, "GEOREF" );
	}

if (congreen == 1 ) then
	RasterApplyContrast2( Green, GreenCon, "Subobject" );
else {
	GreenCon = Green;
	CopySubobjects( Green, GreenCon, "GEOREF" );
	}

if (conblue == 1 ) then
	RasterApplyContrast2( Blue, BlueCon, "Subobject" );
else {
	BlueCon = Blue;
	CopySubobjects( Blue, BlueCon, "GEOREF" );
	}

if (conpan == 1 ) then
	RasterApplyContrast2( Pan, PanCon, "Subobject" );
else {
	PanCon = Pan;
	CopySubobjects( Pan, PanCon, "GEOREF" );
	}

###################################################
### resample RGB rasters to match the Panchromatic band
###################################################

printf( "Resampling RGB rasters to match Pan... \n\n" );

# create temporary rasters for resampled RedCon, GreenCon, and BlueCon
CreateTempRaster( RedRsp, numlinsP, numcolsP, datatypeP$ );
CreateTempRaster( GreenRsp, numlinsP, numcolsP, datatypeP$ );
CreateTempRaster( BlueRsp, numlinsP, numcolsP, datatypeP$ );

ResampleRasterToMatch( RedCon, Pan, RedRsp, "planeproj", "bilinear" );
ResampleRasterToMatch( GreenCon, Pan, GreenRsp, "planeproj", "bilinear" );
ResampleRasterToMatch( BlueCon, Pan, BlueRsp, "planeproj", "bilinear" );

DeleteTempRaster( RedCon );		# delete the temporary rasters for contrast-enhanced
DeleteTempRaster( GreenCon );		# RGB bands
DeleteTempRaster( BlueCon );

###############################################
### Do the color adjustments to make sharpened
### red, green, and blue components
###############################################

printf( "Performing color conversion...\n\n" );

CreateTempRaster( RedSharp, numlinsP, numcolsP, datatypeP$ );
CreateTempRaster( GreenSharp, numlinsP, numcolsP, datatypeP$ );
CreateTempRaster( BlueSharp, numlinsP, numcolsP, datatypeP$ );

### check dialog settings for selected color conversion method


if ( method$ == "HIS" ) {		# convert RGB to HIS, swap P for I,
										# then convert back to RGB

	for each RedRsp {
		r = RedRsp;
		g = GreenRsp;
		b = BlueRsp;
		p = PanCon / 2.55;	# scales to intensity range 0-100
									# expected by color conversion functions

		ConvertRGBtoHIS( 254, r, g, b, h, i, s );

		ConvertHIStoRGB( 254, h, p, s, r, g, b );

		RedSharp = r;
		GreenSharp = g;
		BlueSharp = b;
		}

	}

else if (method$ == "HBS" ) {	# convert RGB to HBS, swap P for Brightness,
										# then convert back to RGB
	for each RedRsp {
		r = RedRsp;
		g = GreenRsp;
		b = BlueRsp;
		p = PanCon / 2.55;	# scales to intensity range 0-100
									# expected by color conversion functions

		ConvertRGBtoHBS( r, g, b, h, br, s );

		ConvertHBStoRGB( h, p, s, r, g, b );

		RedSharp = r;
		GreenSharp = g;
		BlueSharp = b;
		}
	}

else {	# do Brovey transform

	for each RedRsp {

		r = RedRsp;
		g = GreenRsp;
		b = BlueRsp;
		p = PanCon;

		scale = 3 * p / ( r + g + b + 1 );

		RedSharp = r * scale;
		GreenSharp = g * scale;
		BlueSharp = b * scale;

		}
	}

DeleteTempRaster( RedRsp );
DeleteTempRaster( GreenRsp );
DeleteTempRaster( BlueRsp );


###############################################
### Make the output composite
###############################################

printf( "Making the output composite...\n\n" );

#########
### Get info on the output raster for composite

compfilename$ = GetObjectFileName( Comp );
compobjnum = GetObjectNumber( Comp );
compobjname$ = GetObjectName( compfilename$, compobjnum );
compobjdescr$ = GetObjectDescription( compfilename$, compobjnum );

# Delete the Comp object because the stupid RasterRGBToComposite
# function wants to make its own; we will just use the names
# obtained from the GetOutputRaster dialog

DeleteObject( compfilename$, compobjnum );

###################
### Make output composite

RasterRGBToComposite( RedSharp, GreenSharp, BlueSharp, Comp, compfilename$, compobjname$, compobjdescr$, bdepth );
CopySubobjects(Pan, Comp, "GEOREF");
CreatePyramid(Comp);

printf( "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