; IMERG
;---------------------------------------------------------------
;! merges images of different spatial resolutions
;# Task Analysis Imaging
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1997, 2011
;;  Associated Universities, Inc. Washington DC, USA.
;;
;;  This program is free software; you can redistribute it and/or
;;  modify it under the terms of the GNU General Public License as
;;  published by the Free Software Foundation; either version 2 of
;;  the License, or (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU General Public License for more details.
;;
;;  You should have received a copy of the GNU General Public
;;  License along with this program; if not, write to the Free
;;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
;;  MA 02139, USA.
;;
;;  Correspondence concerning AIPS should be addressed as follows:
;;         Internet email: aipsmail@nrao.edu.
;;         Postal address: AIPS Project Office
;;                         National Radio Astronomy Observatory
;;                         520 Edgemont Road
;;                         Charlottesville, VA 22903-2475 USA
;-----------------------------------------------------------------------
IMERG     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
IMERG :  Task which merges high and low res. images
                                   High res. image
INNAME                                Image name (name)
INCLASS                               Image name (class)
INSEQ              0.0      9999.0    Image name (seq. #)
INDISK             0.0         9.0    Image disk drive #
                                   Low res. image
IN2NAME                               Image name (name)
IN2CLASS                              Image name (class)
IN2SEQ            -1.0      9999.0    Image name (seq. #)
IN2DISK            0.0         9.0    Image disk drive #
                                   Output  image
OUTNAME                               Image name (name)
OUTCLASS                              Image name (class)
OUTSEQ            -1.0      9999.0    Image name (seq. #)
OUTDISK            0.0         9.0    Image disk drive #
CHANNEL            0.0             plane number from cubes
UVRANGE            0.0             Min and max baseline (klam.)
                                   defining annulus of overlap
FACTOR             0.0             If > 0.0 , use as norm.
                                   factor for low res. image
AVOPTION                           Averaging option '  ','MEAN'
DOWEIGHT          -1.0        1.0  <= 0 => do not correct for
                                   beams (BMAJ, BMIN, BPA)
BADDISK                            Disks to avoid for scratch.
----------------------------------------------------------------
IMERG
Type: Task
Use:  IMERG merges two input images by fourier transforming both,
      normalizing the second to amplitudes within a U,V annulus of the
      first, then producing an output transform plane consisting of the
      inner plane from the second input, some combination of the two
      within the annulus and the outer plane from the first. The output
      image is the back transform of this merged U,V plane.  The header
      beam parameters (BMAJ, BMIN, BPA) from the two images are used to
      deconvolve the beam of the second image from the second image and
      to convolve the second image with the beam of the first image all
      before the amplitude normalization.  This reconvolution may be
      suppressed with DOWEIGHT.

      NOTE: This task does very little checking of the input files.
      It does require that the images be the same size and that the
      size be an integer power of 2 in both axes.  If your images are
      not a power of 2, PADIM will allow you to raise their size by
      padding with zeros or SUBIM will allow you to reduce their
      size.  The two images should agree in all coordinates - the same
      coordinate types, reference values and pixels, increments,
      rotations, and so forth.  OHGEO may be of use in bring the two
      images into alignment.  If the twop images are not aligned, very
      wrong results will arise, with IMERG doing very little to
      prevent this.
Adverbs:
  INNAME......The high res. image name.      Standard defaults.
  INCLASS.....The high res. image class.     Standard defaults.
  INSEQ.......The high res. image seq. #.    0 => highest.
  INDISK......The high res. image disk drive #. 0 => any.
  IN2NAME.....The low res. image name.  blank => INNAME,
              otherwise standard behavior.
  IN2CLASS....The low res. image class.      Standard behavior
              except blank => 'RBEM' if INCLASS = 'RMAP'
                              'LBEM' if INCLASS = 'LMAP'
                              'IBEM' if INCLASS = anything else
  IN2SEQ......The low res. image seq . #.       0 => INSEQ,
              use -1 to get highest.
  IN2DISK.....The low res. image disk drive #.  0 => any.
  OUTNAME.....The IMERG image name.         Standard defaults.
  OUTCLASS....The IMERG image class.  Standard behavior with
              default = 'RMRG' if INCLASS = 'RMAP'
                        'LMRG' if INCLASS = 'LMAP'
                        'IMRG' if INCLASS = anything else
  OUTSEQ......The IMERG image seq. #.  0 => highest unique.
              If >0; image will be created if new,
              overwritten if image name exists.
  OUTDISK.....The IMERG disk drive no. 0 => highest with space
  BLC.........Bottom left corner of IMERG image.
  TRC.........Top right corner of image; both BLC and TRC
              default so that the whole image is chosen.
  UVRANGE.....The min. and max. baseline in klambda which define the
              annular region of assumed overlap between the low and high
              resolution image transforms.  The normalization of the low
              res. image is based on comparing mean amplitudes in this
              annulus.
  FACTOR......The normalizing factor for the low res. image is imposed
              by using FACTOR > 0.0
  AVOPTION....'MEAN' means to take the average of the 2 data sets over
              the full annulus.  This is best if the two are in good
              agreement.  If they are not, then the abrupt change in
              weights at UVRA(1) and UVRA(2) can cause circular
              sidelobes to appear around sources.  Any other value
              causes a smooth change in the weight from 1.0 for the
              second data at UVRA(1), to 0.5 for both at
              (UVRA(1)+UVRA(2))/2, to 1.0 for the first at UVRA(2).
              (A Gaussian-like function is used.)
  DOWEIGHT....True means to correct the low resolution image by
              deconvolving its beam and convolving the beam of the high
              resolution image before setting the normalization.  False
              means to suppress this operation (equivalent to setting
              the beam parameters to zero in both headers).
              True is > 0; false is <= 0.
  BADDISK.....This array contains the numbers of disks on which it is
              desired that scratch files not be located.  BADDISK has no
              effect on input and output images.
----------------------------------------------------------------
IMERG :  Task which merges high and low resolution images.
DOCUMENTOR: R.Braun NRAO/VLA
DATE OF DOCUMENTATION: 18 November 1987
RELATED PROGRAMS: VTESS,STESS,LTESS
VERSION: 15JAN88

                      PURPOSE

                      REFERENCES

Cornwell T.J., and Evans K.F., "A simple Maximum Entropy
deconvolution algorithm", Astronomy and Astrophysics, (1985)

Burch,S.F, Gull,S.F., and Skilling,J., "Image restoration by a
powerful Maximum Entropy method", Computer Vision, Graphics and
Image processing, 23, 113-128 (1983).
