Вы находитесь на странице: 1из 6

Pemrosesan Citra Page 1 of 6

Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc


By Nemuel Daniel Pah 14/11/05
Module 2
Histogram Manipulation (sliding, stretching, and
complementing)

Class
Image enhancement/Restoration

Description
Histogram sliding is a process to slide histogram distribution of an image
towards brighter or darker gray-scale. The process brighten/darken the input
image. It is performed by adding/subtract a constant value to all pixels in the
image.

Histogram stretching is a process to stretch/shrink histogram distribution of an
image. The process improves the image contrast. It is performed by multiply a
constant value (>1 for stretching or <1 for shrinking) to all pixels in the image.

Histogram complementing is a process to convert bright pixel to dark and dark
pixels to bright proportionally.

Application
Histogram sliding is used to correct over/under exposure image.
Histogram sliding is used to improve contrast in an image.
Histogram complementing is used to the visibility of brightness details
in bright region of an image.

Implementation (histogram sliding)
Calculate histogram of gray level image.
Determine the value of sliding constant by which all histogram
distribution will be shifted.
Add the constant (K) to all pixels:

Output(x,y) = K + Input(x,y)

Manual Calculation (histogram sliding)

Input Output (with K = 100)
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 22 22 22 1 1 1
101 101 122 122 122 101 101 101
1 1 22 22 22 1 1 1
101 101 122 122 122 101 101 101
1 1 22 22 22 1 1 1
101 101 122 122 122 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101
1 1 1 1 1 1 1 1
101 101 101 101 101 101 101 101

Pemrosesan Citra Page 2 of 6
Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc
By Nemuel Daniel Pah 14/11/05
Draw the histogram of both the input and output images, and observe the
effect of histogram sliding to the histogram of the image.


Example (histogram sliding)


An under-exposed image with its histogram


The histogram slided image with (K=100)


Matlab Script (histogram sliding)
The above histogram sliding process was created using the following script
(modul2a.m):

A=imread('gambar1.jpg','jpg');

figure(1);
imshow(A);

figure(2);
imhist(A);
axis([0 255 0 20000]);

Ad=double(A);

ImOut=Ad+100;

ImOut=uint8(ImOut);

figure(3);
imshow(ImOut);

Pemrosesan Citra Page 3 of 6
Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc
By Nemuel Daniel Pah 14/11/05
figure(4);
imhist(ImOut);
axis([0 255 0 20000]);


Implementation (histogram stretching)
Calculate histogram of gray level image.
Determine the stretching factor by which all histogram distribution will
be stretched.
Multiply all pixels with the stretching factor (S):

Output(x,y) = S * Input(x,y)


Manual Calculation (histogram stretching)

Input Output (with S = 100)
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 2 2 2 1 1 1
100 100 200 200 200 100 100 100
1 1 2 2 2 1 1 1
100 100 200 200 200 100 100 100
1 1 2 2 2 1 1 1
100 100 200 200 200 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100
1 1 1 1 1 1 1 1
100 100 100 100 100 100 100 100

Draw the histogram of both the input and output images, and observe the
effect of histogram sliding to improve image contrast.

Example (histogram sliding)


An under-exposed and low-contrast image with its histogram

Pemrosesan Citra Page 4 of 6
Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc
By Nemuel Daniel Pah 14/11/05

The histogram stretched image with (S=255/50)

Matlab Script (histogram sliding)
The above histogram stretched process was created using the following script
(modul2b.m):

A=imread(' gambar1.jpg' ,' jpg' );

figure(1);
imshow(A);

figure(2);
imhist(A);
axis([0 255 0 20000]);

Ad=double(A);

ImOut=Ad*255/50;

ImOut=uint8(ImOut);

figure(3);
imshow(ImOut);

figure(4);
imhist(ImOut);
axis([0 255 0 20000]);


Implementation (histogram complementing)
Calculate histogram of gray level image.
Replace the value of each pixel with its complement value:

Output(x,y) = -1 * Input(x,y) + 255









Pemrosesan Citra Page 5 of 6
Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc
By Nemuel Daniel Pah 14/11/05
Manual Calculation (histogram complementing)

Input
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 20 20 20 1 1 1
254 254 235 235 235 254 254 254
1 1 20 20 20 1 1 1
254 254 235 235 235 254 254 254
1 1 20 20 20 1 1 1
254 254 235 235 235 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254
1 1 1 1 1 1 1 1
254 254 254 254 254 254 254 254

Draw the histogram of both the input and output images, and observe the
effect of histogram complementing to improve image contrast.

Example (histogram complementing)


An image with its histogram



The complemented image with its histogram



Pemrosesan Citra Page 6 of 6
Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul2 HistMan\Modul2.doc
By Nemuel Daniel Pah 14/11/05
Exercise
1. Refer to Matlab manual to understand each line in the above script.
2. Find the appropriate histogram manipulation to enhance gambar1 until
the image is nice and clear, while the piano keys are still sharp.

File Provided
Modul2.doc (this file)
Modul2a.m
Modul2b.m
Modul2c.m
Gambar1.jpg
lena.jpg

Оценить