**Software for viewing images often** makes it possible to manipulate brightness and contrast. The displayed image values are remapped by applying a linear or nonlinear function f in a manner that

where I(x,y) is the original image value, I’(x,y) the remapped image value, and Imin and Imax the smallest and largest intensity values in the histogram, respectively. The argument of f is the image value, normalized to the range 0 to 1, and f would typically return values in the same range. Dmax is the maximum allowable image value in the display unit. Most display units (such as computer monitors and printers) allow the value to range from 0 (black) to 255 (white), and consequently, Dmax = 255. In medical imaging, the contrast or brightness function is often referred to as a window or center. These functions are frequently used for visualization purposes and do not change the actual image values. A closer look at manual contrast enhancement functions is provided in Section 13.1.

**Image contrast can also be enhanced permanently**. In this case the original image value is replaced by the remapped value computed by Equation (2.4). In the simplest case of contrast enhancement, a narrow histogram can be broadened by histogram stretching, a technique whereby image values are remapped according to the equation

where M determines contrast. If M coincides with Dmax in Equation (2.4), no contrast enhancement takes place. If M becomes larger than Dmax, the histogram becomes stretched and its center contrast is amplified. With this amplification, some image values may fall outside the permissible value range and need to be clamped (saturation). Due to the discrete nature of the image values, the remapped histogram will be sparse, with many values that do not occur in the remapped image. Although contrast is enhanced, no information is gained.

A related remapping operation creates a histogram with approximately equal probabilities for all values; this operation is defined as

where the intensity I gets remapped to the new intensity I’ and P(i) is the histogram probability of intensity i. The remapping function defined in Equation (2.6) is designed to provide the most uniform slope possible in the cumulative histogram with the given image value distribution. An implementation for the histogram equalization operation is given in Algorithm 2.2.

**Algorithm 2.2 Histogram equalization as an example of image value remapping [Equation (2.6)]. This algorithm relies on the computation of histc, the cumulative histogram, as well as imin, imax, delta, and nbins in Algorithm 2.1. The input image IM(x,y), with size xmax and ymax, is the same as for Algorithm 2.1, and its values get modified by the histogram equalization process. Note that the final value of buf needs to be rounded if IM(x,y) has integer discretization.**