By Nemuel Daniel Pah 14/11/05 Module 1 Image Histogram & Black-white conversion
Class Image enhancement/Restoration
Description Image histogram is the distribution graph of gray level pixels in an image. It provides graphical representation of how many pixels within an image fall into the various gray-level steps.
image of F16
there are about 1700 pixels in lena.jpg with intensity 100
The normal histogram has at least two humps representing bright objects in the image and dark objects. The valley between the two humps is the threshold value between dark and bright object. The threshold in the F16 histogram happens at gray level 90.
A gray level image can be converted to black & white image by setting all pixels with gray level above threshold to white and all pixels with values below threshold to black.
Application Image segmentation. Segmenting objects in an image.
Implementation (black-white conversion) Calculate histogram of gray level image. Locate the valley between two main humps to define threshold gray level. Set Image(x,y) = 255 if Image(x,y) > threshold
Image(x,y) = 0 if Image(x,y) < threshold
In binary image (black & white), white pixels are represented by 1 while black pixels by 0.
1 5 22 .. 255 7 9 64 Pemrosesan Citra Page 3 of 4 Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul1 Hist\Modul1.doc By Nemuel Daniel Pah 14/11/05
The black &white image of F16 with threshold = 90
Matlab Script The above histogram and black & white conversion was created using the following script:
A=imread('f16.jpg','jpg');
figure(1); imshow(A);
figure(2); imhist(A); axis([0 255 0 2000]);
Ad=double(A);
[y,x]=size(Ad);
for Y=1:y, for X=1:x, if Ad(Y,X)>90, ImOut(Y,X)=1; else ImOut(Y,X)=0; end end end
ImOut=logical(ImOut);
figure(3); imshow(ImOut);
Pemrosesan Citra Page 4 of 4 Copyright JTEUS, 2005 D:\My Documents\JTEUS\Citra\BookOrg\Modul1 Hist\Modul1.doc By Nemuel Daniel Pah 14/11/05 Exercise 1. Refer to Matlab manual to understand each line in the above script. 2. Observe the histogram of images in im1.jpg, im9.jpg, im10.jpg, and lena.jpg. 3. Select proper threshold values for each image and convert to black & white image.