### Basic Gray Level Transformations:

The study of image enhancement techniques is done by discussing gray-level transformation functions. These are among the simplest of all image enhancement techniques. The values of pixels, before and after processing, will be denoted by r and s, respectively. As indicated in the previous section, these values are related by an expression of the form s=T(r), where T is a transformation that maps a pixel value r into a pixel value s. Since we are dealing with digital quantities, values of the transformation function typically are stored in a one-dimensional array and the mappings from r to s are implemented via table lookups. For an 8-bit environment, a lookup table containing the values of T will have 256 entries. As an introduction to gray-level transformations, consider Fig. 1.1, which shows three basic types of functions used frequently for image enhancement: linear (negative and identity transformations), logarithmic (log and inverse-log transformations), and power-law (nth power and nth root transformations).The identity function is the trivial case in which output intensities are identical to input intensities. It is included in the graph only for completeness.

### Image Negatives:** **

The negative of an image with gray levels in the range [0, L-1] is obtained by using the negative transformation shown in Fig.1.1, which is given by the expression

s = L - 1 - r.

Reversing the intensity levels of an image in this manner produces the equivalent of a photographic negative. This type of processing is particularly suited for enhancing white or gray detail embedded in dark regions of an image, especially when the black areas are dominant in size.

### Fig.1.1 Some basic gray-level transformation functions used for image enhancement

**Log Transformations:**

The general form of the log transformation shown in Fig.1.1 is

where c is a constant, and it is assumed that r ≥ 0.The shape of the log curve in Fig. 1.1 shows that this transformation maps a narrow range of low gray-level values in the input image into a wider range of output levels.The opposite is true of higher values of input levels.We would use a transformation of this type to expand the values of dark pixels in an image while compressing the higher-level values.The opposite is true of the inverse log transformation.

Any curve having the general shape of the log functions shown in Fig. 1.1 would accomplish this spreading/compressing of gray levels in an image. In fact, the power-law transformations discussed in the next section are much more versatile for this purpose than the log transformation. However, the log function has the important characteristic that it compresses the dynamic range of images with large variations in pixel values. A classic illustration of an application in which pixel values have a large dynamic range is the Fourier spectrum. At the moment,we are concerned only with the image characteristics of spectra. It is not unusual to encounter spectrum values that range from 0 to or higher.While processing numbers such as these presents no problems for a computer, image display systems generally will not be able to reproduce faithfully such a wide range of intensity values. The net effect is that a significant degree of detail will be lost in the display of a typical Fourier spectrum.

### Power-Law Transformations:

Power-law transformations have the basic form

where c and g are positive constants. Sometimes Eq. is written as

to account for an offset (that is, a measurable output when the input is zero).However, offsets typically are an issue of display calibration and as a result they are normally ignored in Eq. Plots of s versus r for various values of g are shown in Fig. 1.2. As in the case of the log transformation, power-law curves with fractional values of g map a narrow range of dark input values into a wider range of output values,with the opposite being true for high-er values of input levels. Unlike the log function, however, we notice here a family of possible transformation curves obtained simply by varying γ. As expected, we see in Fig.1.2 that curves generated with values of g>1 have exactly the opposite effect as those generated with values of g<1. Finally, we note that Eq. reduces to the identity transformation when c = γ = 1. A variety of devices used for image capture, printing, and display respond according to a power law.By convention, the exponent in the power-law equation is referred to as gamma. The proces used to correct this power-law response phenomena is called gamma correction. For example, cathode ray tube (CRT) devices have an intensity-to-voltage response that is a power function, with exponents varying from approximately 1.8 to 2.5.With reference to the curve for g=2.5 in Fig.1.2, we see that such display systems would tend to produce images that are darker than intended.

### Fig.1.2 Plots of the equation for various values of (c=1 in all cases).

**Piecewise-Linear Transformation Functions:**

The principal advantage of piecewise linear functions over the types of functions we have discussed above is that the form of piecewise functions can be arbitrarily complex. In fact, as we will see shortly, a practical implementation of some important transformations can be formulated only as piecewise functions. The principal disadvantage of piecewise functions is that their specification requires considerably more user input

### Contrast stretching:

One of the simplest piecewise linear functions is a contrast-stretching transformation. Low- contrast images can result from poor illumination, lack of dynamic range in the imaging sensor, or even wrong setting of a lens aperture during image acquisition.The idea behind contrast stretching is to increase the dynamic range of the gray levels in the image being processed.

Figure 1.3 (a) shows a typical transformation used for contrast stretching.

The locations of points (r_{1} _{,} s_{1}) and (r_{2} _{,} s_{2}) control the shape of the transformation

### Fig.1.3 Contrast Stretching (a) Form of Transformation function (b) A low-contrast image

**(c) Result of contrast stretching (d) Result of thresholding.**

function. If r1=s1 and r2=s2, the transformation is a linear function that produces no changes in gray levels. If r1=r2,s1=0 and s2=L-1, the transformation becomes a thresholding function that creates a binary image, as illustrated in Fig. 1.3 (b). Intermediate values of (r_{1} _{,} s_{1}) and (r_{2} _{,} s_{2}) produce various degrees of spread in the gray levels of the output image, thus affecting its contrast. In general, r1 ≤ r2 and s1 ≤ s2 is assumed so that the function is single valued and monotonically increasing.This condition preserves the order of gray levels, thus preventing the creation of intensity artifacts in the processed image.

Figure 1.3 (b) shows an 8-bit image with low contrast. Fig. 1.3(c) shows the result of contrast stretching, obtained by setting (r_{1} _{,} s_{1}) = (r_{min} _{,} 0) and (r_{2} _{,} s_{2}) = (r_{max} _{,} L-1) where r_{min} and r_{max} denote the minimum and maximum gray levels in the image, respectively.Thus, the transformation function stretched the levels linearly from their original range to the full range [0, L-1]. Finally, Fig. 1.3 (d) shows the result of using the thresholding function defined previously,with r1 = r2 = m, the mean gray level in the image.The original image on which these results are based is a scanning electron microscope image of pollen,magnified approximately 700 times.

### Gray-level slicing:

Highlighting a specific range of gray levels in an image often is desired. Applications include enhancing features such as masses of water in satellite imagery and enhancing flaws in X-ray images.There are several ways of doing level slicing, but most of them are variations of two basic themes.One approach is to display a high value for all gray levels in the range of interest and a low value for all other gray levels.This transformation, shown in Fig. 1.4 (a), produces a binary image.The second approach, based on the transformation shown in Fig. 1.4 (b), brightens the desired range of gray levels but preserves the background and gray-level tonalities in the image. Figure 1.4(c) shows a gray-scale image, and Fig. 1.4 (d) shows the result of using the transformation in Fig. 1.4 (a).Variations of the two transformations shown in Fig. 1.4 are easy to formulate.

### Fig.1.4 (a) This transformation highlights range [A, B] of gray levels and reduce all others to a constant level (b) This transformation highlights range [A, B] but preserves all other levels (c) An image (d) Result of using the transformation in (a).

**Bit-plane slicing:**

Instead of highlighting gray-level ranges, highlighting the contributionmade to total image appearance by specific bits might be desired. Suppose that each pixel in an image is represented by 8 bits. Imagine that the image is composed of eight 1-bit planes, ranging from bit-plane 0 for the least significant bit to bit plane 7 for the most significant bit. In terms of 8-bit bytes, plane 0

contains all the lowest order bits in the bytes comprising the pixels in the image and plane 7 contains all the high-order bits.Figure 1.5 illustrates these ideas, and Fig. 1.7 shows the various bit planes for the image shown in Fig.1.6 . Note that the higher-order bits (especially the top four) contain themajority of the visually significant data.The other bit planes contribute tomore subtle details in the image. Separating a digital image into its bit planes is useful for analyzing the relative importance played by each bit of the image, a process that aids in determining the adequacy of the number of bits used to quantize each pixel.

In terms of bit-plane extraction for an 8-bit image, it is not difficult to show that the (binary) image for bit-plane 7 can be obtained by processing the input image with a thresholding gray- level transformation function that (1) maps all levels in the image between 0 and 127 to one level (for example, 0); and (2) maps all levels between 129 and 255 to another (for example, 255).

### Fig.1.6 An 8-bit fractal image

**Fig.1.7 The eight bit planes of the image in Fig.1.6. The number at the bottom, right of each image identifies the bit plane.**