;LOCS  --                                                RJE 10-9-88
;           local contrast stretching by producing minimum of maximum of image
;           and maximum of minimum of image. The latter is subtracted from
;           the first, and this information is used to scale the original.
;expects:   image in a
;result:    image in p or h, depending on configuration
;uses:      images p, q, r
;parameter: window size  (default: 11). Should be larger than largest single
;           structure in the image
;****************************************************************************
parms
int wsize = 11
endparms
IMAGE img

print "windowsize =" wsize

if (((improp fg) & DIS_BIT) == DIS_BIT)
  img = "p"
else
  img = "h"
endif

dis img
min a wsize         ;produce minimum of original
max wsize  >r       ;maximum of previous to shrink max. fields
max a wsize         ;produce maximum of original
min wsize           ;maximum of prev. to shrink min. fields
sub img r >q        ;local contrast image,
sub a r             ;subtract min. from original
div img q 244       ;constant may need adjustment
stop
