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


pca.sml


# Created by Dan Glasser
# 18July03
# Computes principal components of 4 input bands

numeric answer = PopupYesNo("Assuming there are 4 input bands, is this ok?", 1);
if (answer==0)
	Exit();

numeric numbands = 4;

class RVC_RASTER band1, band2, band3, band4;

# assumption is 4 bands
GetInputRaster(band1);
GetInputRaster(band2);
GetInputRaster(band3);
GetInputRaster(band4);

class MATRIX forwardPca, inversePca, inMatrix, outMatrix;

# outMat = (forward * inMat)
outMatrix = CreateMatrix(numbands, 1);
# use to calculate the transformation
inMatrix = CreateMatrix(numbands, 1);
     
forwardPca = CreateMatrix(numbands, numbands);
inversePca = CreateMatrix(numbands, numbands);

# calculate principle components
PrincipalComponents(forwardPca, inversePca, band1, band2, band3, band4);

string filename$ = GetOutputFileName("pca", "Enter an output file name for the Principal Component result", ".rvc");
CreateProjectFile(filename$, "pca result");

# create the rasters to hold principal components
# output values will contain negative numbers so
# always use signed type
class RVC_RASTER pc1, pc2, pc3, pc4;
CreateRaster(pc1, filename$, "pc1", "result of pca: pc1", NumLins(band1), NumCols(band1), "64-bit float");
CreateRaster(pc2, filename$, "pc2", "result of pca: pc2", NumLins(band2), NumCols(band2), "64-bit float");
CreateRaster(pc3, filename$, "pc3", "result of pca: pc3", NumLins(band3), NumCols(band3), "64-bit float");
CreateRaster(pc4, filename$, "pc4", "result of pca: pc4", NumLins(band4), NumCols(band4), "64-bit float");

# all bands have equal number of lins/cols
numeric r, c;
for r = 1 to NumLins(band1)
{
	for c = 1 to NumCols(band1)
	{
		# set inMatrix values to input bands values
		SetMatrixItem(inMatrix, 0, 0, band1[r,c]);
		SetMatrixItem(inMatrix, 1, 0, band2[r,c]);
		SetMatrixItem(inMatrix, 2, 0, band3[r,c]);
		SetMatrixItem(inMatrix, 3, 0, band4[r,c]);
		# out = forward * in
		MultiplyMatrix(outMatrix, forwardPca, inMatrix);
		pc1[r,c] = GetMatrixItem(outMatrix, 0, 0);
		pc2[r,c] = GetMatrixItem(outMatrix, 1, 0);
		pc3[r,c] = GetMatrixItem(outMatrix, 2, 0);
		pc4[r,c] = GetMatrixItem(outMatrix, 3, 0);
	}
}

# do clean up
CloseRaster(band1);
CloseRaster(band2);
CloseRaster(band3);
CloseRaster(band3);
CloseRaster(pc1);
CloseRaster(pc2);
CloseRaster(pc3);
CloseRaster(pc4);
DestroyMatrix(forwardPca);
DestroyMatrix(inversePca);
DestroyMatrix(inMatrix);
DestroyMatrix(outMatrix);


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