Gray Level Transformation | Image Enhancement Techniques – Matlab code

Image enhancement simply means, transforming an image f into image g using T. Where T is the transformation.

The values of pixels in images f and g are denoted by r and s, respectively. As said, the pixel values r and s are related by the expression, s = T(r)  where T is a transformation that maps a pixel value r into a pixel value s.

Enhanced images provide better contrast of the details that images. For example, Medical Image Analysis, satellites images etc.

There are three basic types of transformations functions used for image enhancement.

  • Linear,
  • Logarithmic,
  • Power-Law
Gray-level-transformation-functions
Figure 1 : Gray-level-transformation-functions

Figure 1 shows Plot of various transformation functions. The Identity and Negative curves fall under the category of linear functions. Identity curve indicates that input image is equal to the output image.

The Log and Inverse-Log curves fall under the category of Logarithmic functions and nth root and nth power transformations fall under the category of Power-Law functions.

Image Negation

The negative of an image with grey levels in the range [0, L-1] is obtained by the negative transformation shown in figure above, which is given by the expression as  s = L – 1 – r.   This expression results in reversing of the gray level intensities of the image thereby producing a negative like image. In negative transformation, each value of the input image is subtracted from the L-1 and mapped onto the output image. This is particularly useful for enhancing white or gray details embedded in dark regions of an image.

Download Matlab code for Image Negation Graylevel-transformation-code.zip(67 downloads)

Input Image

Input-Image-Gray-Level-Transformation
Input Image

Output

Gray-Level-Linear-Transformation-Negative-Image
Negative-Image

Log Transformations

The log transformation curve shown in figure 1, is given by following expression, s = c log(1 + r) Where c is a constant and it is assumed that r ≥ 0. The shape of the log curve in figure 1 shows that this transformation maps a narrow range of low-level gray scale intensities into a wider range of output values. And similarly maps the wide range of high-level gray scale intensities into a narrow range of high level output values. The opposite of this applies for inverse-log transform. This transform is used to expand values of dark pixels and compress values of bright pixels.

For example, Log function s = c log(1 + r)  for r varying between 0 and 255, output s results in 0 and 2.41 where c=1. So, the range [0, 2.41] should be mapped to [0, L-1] for getting a meaningful image.

Matlab code Graylevel-transformation-code.zip(67 downloads)

Output

Logarithmic-Image-Gray-level-Transformation-digitalpadm
Logarithmic-Image

Power-Law Transformations

power-law-gamma-transformations
Figure 2: power-law-gamma-transformations

The nth power and nth root curves shown in fig. A can be given by the expression as  s = c r γ  This transformation function is also called as gamma correction. For various values of γ different levels of enhancements can be obtained. It is used to correct power law response phenomena. The different display monitors display images at different intensities and clarity. That means, every monitor has built-in gamma correction in it with certain gamma ranges and so a good monitor automatically corrects all the images displayed on it for the best contrast to give user the best experience. The gamma variation changes ratio of red green & blue along with intensity in color images. The difference between the log-transformation function and the power-law functions is that using the power-law function a family of possible transformation curves can be obtained just by varying the λ. This process  is also called a gamma correction.

Matlab Code Graylevel-transformation-code.zip(67 downloads)

Output

Power-Logarithmic-Image-Gray-level-Transformation-digitalpadm
Power-Logarithmic-Image
Graylevel-transformation-code.zip(67 downloads)