Coyote Graphics Routines

Date: Fri Mar 27 12:14:20 2015

single page | use frames     summary     class     fields     routine details     file attributes


top cgCompressScl

Image Processing

result = cgCompressScl(image [, EXPONENT=float] [, MEAN=float], NEGATIVE=NEGATIVE [, MAX=MAX] [, MIN=MIN] [, OMAX=byte] [, OMIN=byte])

This is a utility routine to perform a compression transformation on an image. For exponent values greater than 1.0, the upper and lower values of the image are compressed and centered on the mean. Larger exponent values provide steeper compression. See pages 68-70 in _Digital Image Processing with MATLAB_ by Gonzales, Wood, and Eddins. The function is used to improve contrast in images. The equation being implemented before scaling between OMIN and OMAX is as follows:

output = 1.0D / ((1.0D + (mean / (Temporary(input) > 1e-16))^exponent) > (1e-16))

Return value

A byte scaled image is returned.


image in required

The image to be scaled. Written for 2D images, but arrays of any size are treated alike.


EXPONENT in optional type=float default=4.0

The exponent in the compression transformation. By default, 4.0.

MEAN in optional type=float default=0.5

Values on either side of the mean will be compressed by the log. The value is a normalized value between 0.0 and 1.0.


If set, the "negative" of the result is returned.

MAX in optional

Any value in the input image greater than this value is set to this value before scaling.

MIN in optional

Any value in the input image less than this value is set to this value before scaling.

OMAX in optional type=byte default=255

The output image is scaled between OMIN and OMAX.

OMIN in optional type=byte default=0

The output image is scaled between OMIN and OMAX.


Examples of compression stretching:

cgLoadCT, 0 ; Gray-scale colors. image = cgDemoData(22) ; Load image. cgImage, image ; No contrast. cgImage, cgCompressScl(image) ; Improved contrast. cgImage, cgCompressScl(image, Exponent=10, Mean=0.65) ; Even more contrast. cgImage, cgCompressScl(image, /Negative, Exponent=5) ; A negative image.

Author information



David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: Coyote's Guide to IDL Programming:


Copyright (c) 2006-2015, Fanning Software Consulting, Inc.


Change History:

Written by: David W. Fanning, 20 February 2006. Fixed a problem with output scaling. 1 July 2009. DWF (with input from Bo Milvang-Jensen). Renamed cgCompressScl from LogScl when I discoverd LogScl implemented the wrong scaling equation. See the documentation in the retired LogScl program for details. 27 March 2015. DWF.

File attributes

Modification date: Fri Mar 27 09:35:11 2015
Lines: 173
Docformat: rst rst