Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Image Processing

0.00/5 (No votes)
6 Dec 2015 1  
Log transform, negative transform, power-law transform, gray transform, histogram stretching, drawing histogram, histogram equalization

Linear Transformation

First, we will look at the linear transformation. Linear transformation includes simple identity and negative transformation. Identity transformation has been discussed in our tutorial of image transformation, but a brief description of this transformation has been given here.

Identity transition is shown by a straight line. In this transition, each value of the input image is directly mapped to each other value of output image. That results in the same input image and output image. And hence is called identity transformation. It has been shown below.

Log Transform

The log transformations can be defined by this formula:

s = c log(r + 1)

Where s and r are the pixel values of the output and the input image and c is a constant. The value 1 is added to each of the pixel values of the input image because if there is a pixel intensity of 0 in the image, then log (0) is equal to infinity. So 1 is added, to make the minimum value at least 1.

s = c log(r + 1)
c = 255/log(1+r)

Negative Transform

The second linear transformation is negative transformation, which is invert of identity transformation. In negative transformation, each value of the input image is subtracted from the L-1 and mapped onto the output image.

s = (L – 1) – r
s = 255 – r

Power-law Transform

There are further two transformations in power law transformations, that include nth power and nth root transformation. These transformations can be given by the expression:

s=cr^γ

This symbol γ is called gamma, due to which this transformation is also known as gamma transformation.

Variation in the value of γ varies the enhancement of the images. Different display devices / monitors have their own gamma correction, that’s why they display their image at different intensity.

This type of transformation is used for enhancing images for different type of display devices. The gamma of different display devices is different. For example Gamma of CRT lies in between of 1.8 to 2.5, that means the image displayed on CRT is dark.

s = 255*(r/255)^gamma

Gray Transform

int gray =(R+G+B)/3;

Using the Code

public Bitmap gray(Bitmap resim)
{
    Color p;
    for (int y = 0; y < resim.Height; y++)
    {
        for (int x = 0; x < resim.Width; x++)
        {
            p = resim.GetPixel(x, y);
            int gri = (p.R + p.G + p.B) / 3;
            resim.SetPixel(x, y, Color.FromArgb(p.A, gri, gri, gri));
        }
    }
    return resim;
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here