DREAM PLAN IDEA IMPLEMENTATION 1
2
3 Introduction to Image Processing Dr. Kourosh Kiani Web: Present to: Amirkabir University of Technology (Tehran Polytechnic) & Semnan University
Lecture 02 Histogram 4
5
6
7
8
9
10
11
H(k) specifies the # of pixels with gray-value k Let N be the number of pixels: P(k) = H(k)/N defines the normalized histogram defines the accumulated histogram Occurrence (# of pixels) Gray Level 12
Histogram Normalized Histogram Accumulated Histogram 13
The image histogram does not fully represent the image P(I) I I H(I) I 0.1 H(I) I 0.1 Pixel permutation of the left image 14
x4 image Gray scale = [0,9] histogram No. of pixels Gray level 15
Gray Level(j) No. of pixels / / / 16 / 16 / 16 / 16 / 16 / 16 s x
Grayscale Histogram 17
(3, 8, 5) 18
19
image histogram 20
valuecount … … PARTIAL IMAGE INFO: 21
Plot of Pixel Count as a Function of Gray Level Value 22
The histogram of an image shows us the distribution of grey levels in the image Massively useful in image processing, especially in segmentation Grey Levels Frequencies 23
24
25
26
OriginalDark Light 27
28
An image has low contrast when the complete range of possible values is not used. Inspection of the histogram shows this lack of contrast. 29
30
rgbI = imread('kourosh.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts); 31
rgbI = imread('kouroshdark.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts); 32
rgbI = imread('kouroshbright.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts); 33
I = imread('pic01.png'); %get image histogram [counts bins]=imhist(I); %show histogram bar(bins,counts); 34
I = imread('pic03.png'); %get image histogram [counts bins]=imhist(I); %show histogram bar(bins,counts); 35
The image shows the spatial distribution of gray values. The image histogram discards the spatial information and shows the relative frequency of occurrence of the gray values. 36
The histogram typically plots the absolute pixel count as a function of gray value: For an image with dimensions M by N I max 37
The graph of relative frequency of occurrence as a function of gray value is also called a histogram: Interpreting the relative frequency histogram as a probability distribution, then: P(I(x,y) = i) = H(i)/(MxN) 38
Interpreting the relative frequency histogram as a probability distribution, then: Curve is called the cumulative distribution function Gray Value P(I(x,y) = i) = H(i)/(MxN) 39
Image histograms consist of peaks, valleys, and low plains Peaks = many pixels concentrated in a few grey levels Plains = small number of pixels distributed over a wider range of grey levels 40
The goal is to modify the gray levels of an image so that the histogram of the modified image is flat. Expand pixels in peaks over a wider range of gray-levels. “Squeeze” low plains pixels into a narrower range of gray levels. Utilizes all gray values equally Example Histogram: Note low utilization of small gray values 41
All gray levels are used equally. Has a tendency to enhance contrast. 42
How are the gray levels in the original image changed to produce the enhanced image? Method 1. Choose points randomly. Method 2. Choice depends on the graylevels of their neighboring points. Computationally expensive. Approximations. 43
Mapping from one set of grey-levels, , to a new set, . Ideally, the number of pixels, N p, occupying each grey level should be: To approximate this, apply the transform Where CH is the cumulative histogram (see next slide) j is the gray value in the source image i is the gray value in the equalized image N p = M*N G i = MAX 0, round CH(j) NpNp 44
ideal G=8 MxN=2400 N p =300 jH(j)CH(j)i CH(j) = H(i) i=0 j
rgbI = imread('ship1.png'); J = histeq(rgbI); imshow(rgbI) figure, imshow(J) %get image histogram [counts bins]=imhist(rgbI); %show histogram figure(3) bar(bins,counts); %get image histogram [counts bins]=imhist(J); %show histogram figure(4) bar(bins,counts); 46
47
48
Histogram Equalization: Example 49
50
COLOR IMAGE 51
52
clc; % Clear the command window. close all; % Close all figures (except those of imtool.) imtool close all; % Close all imtool figures. clear; % Erase all existing variables. workspace; % Make sure the workspace panel is showing. fontSize = 20; % Read in standard MATLAB color demo image. rgbImage = imread('peppers.png'); [rows columns numberOfColorBands] = size(rgbImage); figure (1) imshow(rgbImage, []); redPlane = rgbImage(:, :, 1); greenPlane = rgbImage(:, :, 2); bluePlane = rgbImage(:, :, 3); % Let's get its histograms. [pixelCountR grayLevelsR] = imhist(redPlane); figure(2) %show histogram bar(grayLevelsR,pixelCountR,'r'); xlim([0 grayLevelsR(end)]); % Scale x axis manually. title('Histogram of red plane', 'Fontsize', fontSize); grid on; [pixelCountG grayLevelsG] = imhist(greenPlane); figure(3) %show histogram bar(grayLevelsG,pixelCountG,'g'); xlim([0 grayLevelsG(end)]); % Scale x axis manually. title('Histogram of green plane', 'Fontsize', fontSize); grid on; [pixelCountB grayLevelsB] = imhist(bluePlane); figure(4) %show histogram bar(grayLevelsB,pixelCountB,'b'); xlim([0 grayLevelsB(end)]); % Scale x axis manually. title('Histogram of blue plane', 'Fontsize', fontSize); grid on; 53
54
Questions? Discussion? Suggestions ? 55
56