Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#
Tip/Trick

Image Processing

Rate me:
Please Sign up or sign in to vote.
3.67/5 (5 votes)
6 Dec 2015CPOL2 min read 29.7K   826   7   7
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

C++
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;
}

Image 1

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionplease remove binary artefacts from your archive Pin
sx200810-Dec-15 9:46
sx200810-Dec-15 9:46 
BugSelecting Histogram from Combo causes Exception Pin
Ehsan Sajjad6-Dec-15 23:41
professionalEhsan Sajjad6-Dec-15 23:41 
GeneralRe: Selecting Histogram from Combo causes Exception Pin
Bilal Çalım8-Dec-15 1:42
Bilal Çalım8-Dec-15 1:42 
GeneralRe: Selecting Histogram from Combo causes Exception Pin
Ehsan Sajjad8-Dec-15 2:42
professionalEhsan Sajjad8-Dec-15 2:42 
GeneralRe: Selecting Histogram from Combo causes Exception Pin
Bilal Çalım8-Dec-15 21:11
Bilal Çalım8-Dec-15 21:11 
GeneralRe: Selecting Histogram from Combo causes Exception Pin
lobotomy23-Dec-15 10:26
professionallobotomy23-Dec-15 10:26 
GeneralRe: Selecting Histogram from Combo causes Exception Pin
Bilal Çalım26-Dec-15 7:28
Bilal Çalım26-Dec-15 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.