Help for SIZEMGN

PURPOSE:
SIZEMGN is a VICAR applications program which may be used to magnify or compress
the size of an image and/or change its aspect ratio.  This program is largely
identical to program SIZE, but contains special features to support Magellan
(MGN) processing not present in the latter program.  

EXECUTION STATEMENT:

      SIZEMGN  INP=IPIC  OUT=OPIC  user-parameters...

where IPIC is the input image and OPIC is the output image.  IPIC and OPIC
may be in byte, halfword (16-bit integer), fullword (32-bit integer), or
floating point (REAL*4) data format.

OPIC will normally have the same data format as IPIC.  Use the OFORM parameter
to change the output format.

SIZEMGN performs  bilinear interpolation to magnify or compress the image.
The 'NOIN keyword may be used to suppress interpolation.  See sections on image
magnification and reduction below.

OPERATION:

The size of the output image is specified in one of two ways:

(1) Explicitly specifying it with the NL and NS parameters:

        SIZEMGN  INP  OUT  NL=500  NS=500
    or  SIZEMGN  INP  OUT  SIZE=(1,1,500,500)

(2) Specifying a magnification or compression (zoom) factor:

        SIZEMGN  INP  OUT  ZOOM=3		! 3x magnification
        SIZEMGN  INP  OUT  ZOOM=-2         ! 2x compression
    or  SIZEMGN  INP  OUT  ZOOM=0.5        ! 2x compression

The ZOOM factor can be a floating point value.
A negative ZOOM results in image compression.  I.e. ZOOM= -2.5 is the
same as ZOOM=0.4

Note the if both NL,NS ans ZOOM are specified, the ZOOM parameter will
determine the magnification/compression factor and NL,NS will determine the
size of the output image.

Independent zooms may be specified in the line (vertical) and sample
(horizontal) directions:

        SIZEMGN  INP  OUT  LZOOM=2  SZOOM=3
        SIZEMGN  INP  OUT  LZOOM=3  SZOOM=-2

As the last example implies, the image may be magnified in one direction
and compressed in the other.

The AREA parameter may be used to restrict processing to an area of the
input image.  For example:

		SIZEMGN  IPIC  OPIC  ZOOM=-3  AREA=(10,10,100,100)
is equivalent to
		COPY  IPIC  IDS  (10,10,100,100)
		SIZEMGN  IDS  OPIC  ZOOM=-3

The output data format may be different from the input format (see OFORM
keyword).  The image DNs may be optionally rescaled at this point via parameter
SCALE.  Note that rescaling may be necessary when converting to a smaller data
format (e.g. halfword-to-byte).  If a sample value is outside the range of the
output format (e.g. 0 to 255 DN for byte data), the output DN will be truncated.
The output DN range may be further limited via the LIMITS parameter.

SPECIFYING THE SIZE OF THE OUTPUT IMAGE:

The size of the output image is specified either by entering the number of
lines and samples in the VICAR size field, or by specifying a magnification
or compression factor via the ZOOM, LZOOM, or SZOOM parameters:

Ex:  Enlarging a 3x3 image to a 9x9 image can be achieved in the
     following equivalent ways:

		SIZEMGN  A  B  SIZE=(1,1,9,9)
        or      SIZEMGN  A  B  NL=9  NS=9
	or	SIZEMGN  A  B  ZOOM=3
        or      SIZEMGN  A  B  LZOOM=3  SZOOM=3

If the output image size is specified by entering the number of lines and
samples, then the ZOOM factor is determined by computing the ratio between
the output and input picture dimensions.  Independent ZOOM factors are
computed in the line and sample dimensions, and may result in a change in
the image aspect ratio:

	z1=NLO/NLI		z2=NSO/NSI

where the input image size is NLI x NSI and the output image size is NLO x NSO.
The computations are performed in floating point, so that the output picture
size is not necessarily a multiple of the input picture size (i.e. z1 and
z2 are floating-point numbers).

The ZOOM factors may be specified via the ZOOM parameter,
		    ZOOM=z
where z1=z2=z, or independently via the LZOOM and SZOOM parameters:
		LZOOM=z1  SZOOM=z2

When the zoom factor is an integer, it is identical in function to the ZOOM
option in program XVD.  If z is positive, the input picture size
is multiplied by z.  If z is negative, the picture size is divided by -z.
Note that z=-2 is equivalent to z=0.5.

Specification of a zoom factor does not override the corresponding NL and/or 
NS values in the VICAR SIZE field.  If a value of NL or NS is specified that 
is smaller than ZOOM*(input NL or NS), then the image will be truncated in
that dimension.  If greater, then a blank area will be appended on the
bottom or right edge, respectively.

The IOFFSET parameter may be used to start the output image at a (line,sample)
coordinate other than (1,1).  Let the input image be:

                           1  2  3
                           2  3  4
                           3  4  5

then
		SIZEMGN  INP  OUT  NL=8  NS=8  ZOOM=2  IOFFSET=(2,2)  'NOIN

will result in the following:

                    0  0  0  0  0  0  0  0
                    0  1  1  2  2  3  3  0
                    0  1  1  2  2  3  3  0
                    0  2  2  3  3  4  4  0
                    0  2  2  3  3  4  4  0
                    0  3  3  4  4  5  5  0
                    0  3  3  4  4  5  5  0
                    0  0  0  0  0  0  0  0

IMAGE MAGNIFICATION:

The following example illustrates how image magnification is treated. Let
the input picture A be a 3x3 image as follows:

			       2  5  8
			A  =   5  8 11
			       8 11 14

The statement
		SIZEMGN  A  B  SIZE=(1,1,9,9)  'NOIN
	or	SIZEMGN  A  B  ZOOM=3  'NOIN

will produce a 9x9 output image B by replicating each input sample into a
3x3 pixel area:

		       2  2  2  5  5  5  8  8  8
		       2  2  2  5  5  5  8  8  8
		       2  2  2  5  5  5  8  8  8
		       5  5  5  8  8  8 11 11 11
		B  =   5  5  5  8  8  8 11 11 11
		       5  5  5  8  8  8 11 11 11
		       8  8  8 11 11 11 14 14 14
		       8  8  8 11 11 11 14 14 14
		       8  8  8 11 11 11 14 14 14

The statement
		SIZEMGN  A  B  SIZE=(1,1,9,9)  ZOOM=3

will produce a 9x9 output image by interpolating between the four nearest
neighbors and extrapolating around the picture borders.

		       0  1  2  3  4  5  6  7  8
		       1  2  3  4  5  6  7  8  9
		       2  3  4  5  6  7  8  9 10
		       3  4  5  6  7  8  9 10 11
		B  =   4  5  6  7  8  9 10 11 12
		       5  6  7  8  9 10 11 12 13
		       6  7  8  9 10 11 12 13 14
		       7  8  9 10 11 12 13 14 15
		       8  9 10 11 12 13 14 15 16

As in the no-interpolation case above, each input sample has been "blown up"
to fill a 3x3 area.  However, because interpolation is performed, the input
sample values equal the output sample values only at the geometric centers
of these 3x3 areas.

Note that the magnified image output by SIZEMGN differs slightly from what one
might obtain using GEOM, MGEOM, or GEOMA. The user may find it instructive
to attempt to achieve an identical result as the example above by using GEOM
or GEOMA.

IMAGE COMPRESSION:

Image compression is treated as the functional inverse of image magnification.
Unless the keyword 'NOIN is specified, the compression is performed via area
averaging.  To illustrate, let picture B be the 9x9 image of our previous
example:

		       0  1  2  3  4  5  6  7  8
		       1  2  3  4  5  6  7  8  9
		       2  3  4  5  6  7  8  9 10
		       3  4  5  6  7  8  9 10 11
		B  =   4  5  6  7  8  9 10 11 12
		       5  6  7  8  9 10 11 12 13
		       6  7  8  9 10 11 12 13 14
		       7  8  9 10 11 12 13 14 15
		       8  9 10 11 12 13 14 15 16

The statement:
		SIZEMGN  B  C  ZOOM=-3

will cause each output pixel to be computed by averaging a 3x3 area of
the input image.  For example, output pixel (1,1) = (0+1+2+1+2+3+2+3+4)/9
The resulting output image C will be identical to our original input image A:

			       2  5  8
			C  =   5  8 11
			       8 11 14

The area averaging operation is extended to non-itegral zoom factors by
assigning fractional weights to samples around the area margins, and unit
weights to interior samples. The output sample is then the weighted samples
divided by the sum of their weights.

If the keyword 'NOIN is specified,

		SIZEMGN  IPIC  OPIC  ZOOM=-N  'NOIN

then no pixel interpolation is performed.  The output image is generated
by selecting every Nth image line from IPIC, and every Nth pixel of each of
these lines, begining with pixel (1,1).  Note that when the output picture
is several times smaller than the input picture, most of the samples in the
input image are ignored in the generation of the output image.

To illustrate, let picture B be the 9x9 image of our previous example:

		       0  1  2  3  4  5  6  7  8
		       1  2  3  4  5  6  7  8  9
		       2  3  4  5  6  7  8  9 10
		       3  4  5  6  7  8  9 10 11
		B  =   4  5  6  7  8  9 10 11 12
		       5  6  7  8  9 10 11 12 13
		       6  7  8  9 10 11 12 13 14
		       7  8  9 10 11 12 13 14 15
		       8  9 10 11 12 13 14 15 16

The statements:
		SIZEMGN  B  C  ZOOM=-3  'NOIN
		SIZEMGN  B  D  ZOOM=-3  'NOIN  AREA=(2,2,8,8)

will generate 3x3 output images C and D of the form:

		0  3  6		       2  5  8
	 C  =	3  6  9		D  =   5  8 11
		6  9 12		       8 11 14

Note the use of the AREA parameter to begin the resampling at a point other
than pixel (1,1).

The input image may be compressed by a non-integral zoom factor r:

		SIZEMGN  IPIC  OPIC  ZOOM=r  'NOIN

where r is a floating point number between 0 and 1.  Each output sample is
generated by determining where it comes from in the input image and selecting
the sample closest to this point.

UPDATING OF MAP PROJECTION LABEL INFORMATION:

If the input image has map projection labels, the projection information
will be updated to reflect changes in the geometry as a result of size
changes and image offsets (see AREA and IOFFSET parameters).  A new map
projection history label is added and the map projection property label
is updated.

If the map projection is POINT PERSPECTIVE, the following label items are
recomputed:

    FOCAL_PLANE_SCALE
    OPT_AXIS_INTERCEPT_LINE
    OPT_AXIS_INTERCEPT_SAMPLE
    PLANET_CENTER_LINE
    PLANET_CENTER_SAMPLE

For all other projections, the following label items are recomputed:

    LINE_PROJECTION_OFFSET
    SAMPLE_PROJECTION_OFFSET
    MAP_SCALE
    MAP_RESOLUTION

If either MAP_SCALE or MAP_RESOLUTION is missing from the input projection
label, it is computed from the other using the relationship: 

                      PI
     MAP_RESOLUTION = --- * A_AXIS_RADIUS/MAP_SCALE
                      180

EXAMPLES:

Let the input image be a 100 x 100 byte picture. The following equivalent
statements will magnify the input image by a factor of 2.5:

		SIZEMGN  A  B  SIZE=(1,1,250,250)
		SIZEMGN  A  B  ZOOM=2.5

To blow up a 50x50 area from the center of the picture by a factor of 4:

		SIZEMGN  A  B  ZOOM=4  AREA=(26,26,50,50)

To average all the lines of an image together, use

		SIZEMGN  A  B  NL=1

The following equivalent statements magnify the line direction by 2 and
shrinks the sample direction by 2:

		SIZEMGN  A  B  SIZE=(1,1,200,50)
		SIZEMGN  A  B  LZOOM=2  SZOOM=-2

MAGELLAN SPECIFIC OPTIONS:

Special code has been added to SIZEMGN to convert Magellan data to units of
volts before compressing the image.  The pixels are subsequently converted
back to DN prior to output.  Both input and output images must be in byte
format.  The input image must contain more than one sample per line.
The Magellan option is implemented for image compression and integral ZOOM
values only.  The NOIN, LIMITS and SCALE parameters are illegal with this
option.

The Magellan option is currently implemented using two competing algorithms:
If keyword 'LOOKUP is specified, the program uses tables input from external
files to convert the input samples from DNs to voltages and to convert the
output samples from voltages to DNs.  If the keyword 'VOLTS is specified,
the program performs the conversions using tables computed internally.  The
'LOOKUP algorithm is 20 percent faster, but introduces a random error of 0.5 DN
with a maximum error of 20 DN.  The error is greatest at low DN levels.

The next two sections describe the LOOKUP and VOLTS keywords.
LOOKUP KEYWORD:

If the 'LOOKUP keyword is specified, the DN-to-volts and volts-to-DN tables
are read from files specified by the DVDATA and VDDATA parameters.  Both lookup
tables may be generated via VICAR procedure SIZELOOKUP.  If defaulted, files
MGNSIZED.DAT and MGNSIZEV.DAT are read from MGNLIB.

The DN-to-volts table is in fullword (INTEGER*4) data format and contains
256 entries (for DNs 0 to 255).  The entries in this table are assumed to be
non-negative.  The table must be input from a file in standard VICAR image
format, consisting of one line of 256 samples.

The Volts-to-DN table is in byte format and contains at least N entries, where
N is the maximum value stored in the DN-to-volts table (N < 1250000).

Ex:    SIZEMGN  IPIC  OPIC  ZOOM=-3  'LOOKUP
  Lookup tables MGNSIZED.DAT and MGNSIZEV.DAT are automatically accessed from
  directory MGNLIB.

Ex:    SIZELOOKUP  OUT_DIR=DEV:[JOE123]
       SIZEMGN  IPIC  OPIC  ZOOM=-4  'LOOKUP  	  DVDATA=DEV:[JOE123]MGNSIZED.DAT  	  VDDATA=DEV:[JOE123]MGNSIZEV.DAT

  The procedure SIZELOOKUP is used to compute external lookup tables
  MGNSIZED.DAT and MGNSIZEV.DAT in directory DEV:[JOE123].  The DVDATA and
  VDDATA parameters are used to input these files to SIZEMGN.

VOLTS KEYWORD:

If the 'VOLTS keyword is specified, conversion tables are computed internally
using the following formulas:
	a)  v = 10**((d-b)/a)
        b)  d = a*logv + b
where v=volts, d=DN, a=slope, b=offset.  The slope and offset may be specified
via the SLOPE and OFFSET parameters.

The volts-to-DN conversion is accomplished by computing a 2250 entry logrithmic
table.  When the default slope (50) is used, this table introduces a 0.1 DN
random error, with a maximum error of 1 DN.  Larger slopes will result in 
correspondingly larger errors.

PROGRAM RESTRICTIONS:

Both IPIC and OPIC may be up to 20,000 pixels in width (sample size) and of
arbitrary length (line or vertical dimension).

The input image may be on tape or disk.  However, the output image must be on
random-access disk storage.


PROGRAM HISTORY:

Written by: Gary Yagi, 26 January 1976
Cognizant programmer: Ray Bambery

Revision history:

    Jun 06, 2012 - R. J. Bambery - gfortran 4.6.3 changed all dimension (1) values to (*)
                                in subroutines to avoid
        "Fortran runtime error: Index '2' of dimension 1 of array 'id' above upper bound of 1"
    06 May 1011 R.J. Bambery - removed warning messages by gfortran 4.4.4 
                    compiler
    10 Feb 04  lwk  Renamed SIZE to SIZEMGN in order to preserve Magellan
		            functionality removed from new version of SIZE.

For previous history, see SIZE.PDF.


PARAMETERS:


INP

Input image.

OUT

Output image.

SIZE

Output picture size.

NL

Output number of lines picture.

NS

Output number of samples picture.

OFORM

Output data format. Valid keywords are BYTE, HALF, FULL, or REAL.

AREA

Input image area to be SIZEd

IOFFSET

Offset output image: OFFSET=(SLO,SSO)

NOIN

Specifies no interpolation.

ZOOM

Specifies the ZOOM factor.

LZOOM

Vertical zoom factor.

SZOOM

Horizontal zoom factor.

SCALE

Scale applied to output values.

LIMITS

Lower and upper limits of DN range.

LOOKUP

Magellan specific option to compress an image.

VDDATA

Magellan specific option. Specifies lookup table for converting volts to DNs.

DVDATA

Magellan specific option. Specifies lookup table for converting DNs to volts.

VOLTS

Magellan specific option to compress an image.

SLOPE

Magellan specific option Specifies slope of volts-to-dn conversion

OFFSET

Magellan specific option Specifies offset of volts-to-dn conversion.

DEBUG

Print status message.

See Examples:


Cognizant Programmer: