FUNCTION CutMinMax, imageP, $
	MINIMUM = minimum, MAXIMUM = maximum
; NAME:
; 	CutMinMax
; PURPOSE
;	Cut the lowest and/or the highest value of an array,
;	and replace it by the second lowest, second highest value,
; 	respectively.
; CATEGORY:
;	Image Processing
; CALLING SEQUENCE:
;	CutMinMax, image
; INPUT PARAMETER:
;	image: The two-dimensional array to be processed
; RESULT:
;	The processed two-dimensional array.
; KEYWORDS:
;	/MINIMUM: to set if the minimum has to be cut
;	/MAXIMUM: to set if the maximum has to be cut
; -
;MODIFICATION HISTORY
;	Created: June 1991, A.Csillaghy

  IF N_Elements( imageP ) EQ 0 THEN BEGIN
    Error, 15, 'Cut Minimum and/or Maximum'
    RETURN, -1
  ENDIF ELSE image = imageP

  IF Keyword_Set(MINIMUM)  THEN $
    image(Where(image EQ Min(image))) = $
	Min(image( (Where( image GT Min(image)) > 0 ) ) )
  IF Keyword_Set(MAXIMUM) THEN $
    image(Where(image EQ Max(image))) = $
	Max(image( (Where( image LT Max(image)) > 0 ) ) )

  RETURN, image
END