Help for FFTFIT

PURPOSE:
"fftfit" will modify a complex Fourier transform created by "fft2" or "fft22"
in one of two ways:

1. The complex Fourier transform will be multiplied by an input picture.
2. The amplitude of the complex Fourier transform will be made proportional
   to an input picture.  Phase will not be altered.

"fftfit" can be used to force pictures to have identical power spectra and
can provide for the execution of detailed filters.

 
EXECUTION:

Example - Basic Parameters MULT and HALF

fftfit  INP=(FT,PIX)  OUT=FTOUT  'MULT  'HALF

Complex Fourier transform FT, which must have been created by "fft2" or "fft22",
is input to "fftfit" along with the input picture PIX which is used to modify
the transform.  The modified Fourier transform will be sent to FTOUT.  This
command demonstrates only MULT and HALF; all other options default to various
values as described in the examples below.  'MULT specifies that the
transform is to be multiplied by the input picture; this is the first mode
listed above.  Otherwise, and by default, the transform is made proportional
to the input picture.  'HALF specifies that PIX is a halfword picture;
the default is to read the input image as byte data. 


Examples - Controlling FFTOUT phase by specifying the correspondence between
	   (line,sample) in PIX and (line,sample) in FT.

fftfit  INP=(FT,PIX)  OUT=FTOUT  LINE=10  SAMPLE=15

This example shows one way in which to specify the correspondence between PIX
and FT.  The LINE keyword indicates that line 10 in PIX corresponds with line
one (the DC line) in FT.  The default is for LINE to equal NL/2 + 1 where NL
is the number of lines in FT.  The SAMPLE keyword specifies the sample number
in PIX which corresponds with column one (the DC column) in FT.  The default
is NPIX/2 + 1 where NPIX is one eighth the number of samples in FT.  All
other parameters default as described in the relevant examples.

fftfit  INP=(FT,PIX)  OUT=FTOUT  'FIND

The FIND keyword indicates that LINE and SAMPLE described above are to be
determined from PIX by locating the position of the largest DN value in PIX.
If more than one pixel has the maximum DN value, the centroid of all maximum
DN values is selected.  The default is not to perform this operation.


Examples - Controlling scaling of PIX before application to transform FT.

fftfit  INP=(FT,PIX)  OUT=FTOUT  SCALE=2.0

SCALE specifies the scaling factor applied to the input image before
processing. 
    In the multiplicative mode, SCALE (by default) equals one divided by the
mean DN value measured within the sampling area specified by the SET keyword or
its defaults; in the matching mode, where FTOUT is made proportional to the
input picture, SCALE equals A-bar divided by the mean DN value, where A-bar is
a similarly-determined reference amplitude in FT. 
    The SCALE keyword allows the user to bypass all of these calculations and
explicitly specify the scaling factor to be used.  All other parameters in this
example are allowed to default. 

fftfit  INP=(FT,PIX)  OUT=FTOUT  SET=(3,5)

SET directs the program to calculate the scaling value SCALE from an area
defined by the integer values, 3 and 5 in this example, in both PIX and FT.
A-bar is obtained from the mean amplitude in the shaded area bounded by 
N3 and N4 in the upper left quadrant to FT (see figure).

		N3	N4		NPIX=NS/8
	+-------+-------+----------------------- 	|DC	|///////|			|DC
	|	|///////|			|
      N3+-------+///////|			|
	|///////////////|			|	matrix of 
	|///////////////|			|	complex FFT values
      N4+---------------+			|
	|					|
	|					|
	|					|
	|					|
	|					|
      NL+---------------------------------------          DC					 DC

The mean DC value is computed from the corresponding area in PIX starting at 
(LINE,SAMPLE) rather than at (1,1) as in FT.  Default is SET=(2,3).


Restrictions:
1. PIX should have the same number of lines and samples as FT. This assures
   a one to one correspondence between PIX pixels and complex FT pixels.


OPERATION:

"fftfit" allows two modes:

1. Force the amplitude of the Fourier transform (FT) to be a scaled replica
   of the picture (PIX).

|FTOUT(i,j)| is proportional to DN(i,j).

FTOUT(i,j) = FT(i,j) * SCALE * DN(i,j) / |FT(i,j)|

                       DN(i,j)     A-bar
	   = FT(i,j) * ------- * ---------
		       mean DN   |FT(i,j)|

where SCALE equals A-bar divided by the mean DN value and |FT| represents
the amplitude SQRT( a**2 + b**2) = |a + bi|.

2.  Multiply the FT by PIX.
						   DN(i,j)
FTOUT(i,j) = FT(i,j) * SCALE * DN(i,j) = FT(i,j) * -------
						   mean-DN


In both cases the DC term of FT is set apart from the transformation and is
never altered.  Whatever the result, the mean of the inverse transform of
FTOUT will always be the same as that of the original picture whose transform
is FT.

It is important to note the significance of the LINE, SAMPLE keywords.  These
values point to the pixel in PIX which will be centered on the DC term (1,1)
in the FT picture.  In the majority of cases PIX will be a symmetrical 
function such as a gaussian, etc.  LINE and SAMPLE will usually refer to the
center of the symmetry of this function.  When this is the case "fftfit" will be
able to divide up PIX into symmetrical quadrants and match them to the
complex format of FT (with DC in the corners).  If LINE, SAMPLE do not refer to
to a symmetry point FTOUT will be asymmetrical and the inverse transformation
will produce the real part of a complex picture (if PIX is asymmetrical) or a
displaced image (if PIX is symmetrical but just off center).

FT can be created with either "fft2" or "fft22". DC remains the same for both 
complex formats but the latter has been transposed relative to the former
(rows become columns).  "fftfit" assumes the user has organized PIX such that
it is compatible with the appropriate FT format.  Symmetrical cases are 
invariant.  One can convert PIX from one format to the other with two 
executions of "flot".

It is suggested that when the inverse transform is made (particularly in the
amplitude matching mode) the output picture be halfword.  Most operations
will cause some DN's to lie outside the byte range and halfword formatting
will allow access to these pixels.


WRITTEN BY:  J. J. Lorre, 31 October 1977
COGNIZANT PROGRAMMER:  A. S. Mazer
REVISION 1:  A. Scop, 31 October 1994   Made portable for UNIX


PARAMETERS:


INP

STRING - Image and transform files

OUT

STRING - Output transform file

MODE

KEYWORD - MULTiplication mode flag (AMPMATCH, MULT)

LINE

INTEGER - Image line corr to FT line 1

SAMPLE

INTEGER - Image samp corr to FT sample 1

FIND

KEYWORD - Computed-correspondence flag (FIND)

SCALE

REAL - Scaling factor

SET

INTEGER - Area for auto SCALE computation

See Examples:


Cognizant Programmer: