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


lincombo.sml


# lincombo.sml
# Creates Raster objects that are linear combinations of any
# number of input Raster objects.

# creating and filling in the transform matrix
#
# the matrix size is determined by the number 
# of input and output rasters:
# number of columns = number of input rasters + 1
# number of rows = number of output rasters
# column 1 has offset coefficients
# columns 2 to (N + 1) hold the coeffients for the N output rasters
# in general if:
# N = number of output rasters, M = number of input rasters
# 
# outRasterN[r,c] =   transformMatrix[N-1,0]
#                   + transformMatrix[N-1,1] * inRaster1[r,c]
#                   + transformMatrix[N-1,2] * inRaster2[r,c]
#                   + ...
#                   + transformMatrix[N-1,M] * inRasterM[r,c]
# 
# our matrix will be:
# | 0.0  .213  .715  .072 |  - coeff. for the first raster
# | 0.0  .333  .333  .333 |  - coeff. for the second raster
#
# our output rasters are created using these formulas:
#
# Lcombo1[r,c] = 0.0 + (.213 * Rred[r,c]) 
# 	                  + (.715 * Rgreen[r,c]) 
#                    + (.072 + Rblue[r,c])
#
# Lcombo2[r,c] = 0.0 + (.333 * Rred[r,c])
# 	                  + (.333 * Rgreen[r,c])
#                    + (.333 + Rblue[r,c])
#



# Compute brightness Raster from rgb rasters
# the coefficents are only approximate, correct for NTSC(1953)

raster Rred, Rgreen, Rblue;
class MATRIX transform;

# set up variables to hold values for flags
numeric flagNoAutoscale = 0;
numeric flagAutoscale = 1;

GetInputRaster(Rred);
GetInputRaster(Rgreen);
GetInputRaster(Rblue);

numeric numInputRasters = 3;
numeric numOutputRasters = 2;
transform = CreateMatrix(numOutputRasters, numInputRasters + 1);

# output Raster one
# set matrix items (coefficients) equal to correct 
# red, green, and blue contributions to brightness
SetMatrixItem(transform, 0, 0, 0.0);  # sets offset to zero
SetMatrixItem(transform, 0, 1, .212); # red
SetMatrixItem(transform, 0, 2, .715); # green
SetMatrixItem(transform, 0, 3, .072); # blue

# output Raster two
# other method to compute brightness - not as good
# set coefficients for average of red, green, and blue
SetMatrixItem(transform, 1, 0, 0.0);  # sets offset to zero
SetMatrixItem(transform, 1, 1, .333); # red
SetMatrixItem(transform, 1, 2, .333); # green
SetMatrixItem(transform, 1, 3, .333); # blue

# get output RVC file name

string outRVCFile$ = GetOutputFileName("", "Select output RVC file", "rvc");

numeric flags = 0; # no auto scale
RasterLinearCombination(transform, outRVCFile$, "Lcombo", 
	"Linear Combinations Test :", flags, Rred, Rgreen, Rblue);

DestroyMatrix(transform);
CloseRaster(Rred);
CloseRaster(Rgreen);
CloseRaster(Rblue);


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