560 likes | 717 Views
DREAM. IDEA. PLAN. IMPLEMENTATION. Introduction to Image Processing. Present to: Amirkabir University of Technology (Tehran Polytechnic) & Semnan University. Dr. Kourosh Kiani Email: kkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.ir Email : Kourosh.kiani@semnan.ac.ir
E N D
DREAM IDEA PLAN IMPLEMENTATION
Introduction to Image Processing Present to:Amirkabir University of Technology (Tehran Polytechnic) & Semnan University Dr. Kourosh Kiani Email: kkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.ir Email: Kourosh.kiani@semnan.ac.ir Web: www.kouroshkiani.com
Lecture 02 Histogram
The Image Histogram Occurrence (# of pixels) Gray Level • 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
Histogram Normalized Histogram Accumulated Histogram
Examples P(I) P(I) 1 1 0.5 I I H(I) H(I) 0.1 0.1 I I Pixel permutation of the left image • The image histogram does not fully represent the image
No. of pixels 6 5 4 3 2 1 Gray level 4x4 image 0 1 2 3 4 5 6 7 8 9 Gray scale = [0,9] histogram Example
(3, 8, 5) What is histogram?
Histogram image histogram
Histogram PARTIAL IMAGE INFO: 117 83 59 59 68 77 84 94 82 67 62 70 83 86 85 81 71 65 77 89 86 82 76 67 72 90 97 86 66 54 68 104 121 107 85 46 58 89 138 165 137 91 38 80 147 200 211 187 138 40 80 149 197 202 187 146 56 76 114 159 181 160 113
Image Histogram Plot of Pixel Count as a Function of Gray Level Value
Image Histograms Frequencies Grey Levels The histogram of an image shows us the distribution of grey levels in the image Massively useful in image processing, especially in segmentation
Histogram An image has low contrast when the complete range of possible values is not used. Inspection of the histogram shows this lack of contrast.
rgbI = imread('kourosh.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts);
rgbI = imread('kouroshdark.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts);
rgbI = imread('kouroshbright.jpg'); grayI = rgb2gray(rgbI); %get image histogram [counts bins]=imhist(grayI); %show histogram bar(bins,counts);
I= imread('pic01.png'); %get image histogram [counts bins]=imhist(I); %show histogram bar(bins,counts);
I= imread('pic03.png'); %get image histogram [counts bins]=imhist(I); %show histogram bar(bins,counts);
Histogram Equalization • 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.
Histogram Equalization • The histogram typically plots the absolute pixel count as a function of gray value: For an image with dimensions M by N I max
Probability Interpretation • 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)
Gray Value Cumulative Density Function • Interpreting the relative frequency histogram as a probability distribution, then: • Curve is called the cumulative distribution function P(I(x,y) = i) = H(i)/(MxN)
Histogram Equalization • 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
Histogram Equalization • 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
Desired Histogram • All gray levels are used equally. • Has a tendency to enhance contrast.
Brute Force 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 graylevelsof their neighboring points. Computationally expensive. Approximations.
CH(j) i = MAX 0, round -1 Np M*N Np = G Histogram Equalization • Mapping from one set of grey-levels, I, to a new set, O. • Ideally, the number of pixels, Np, 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
j CH(j) = S H(i) i=0 Example j H(j) CH(j) i 100 900 1600 2100 2200 2300 2400 2400 0 100 0 1 800 2 G=8 MxN=2400 Np=300 2 700 4 3 500 6 4 100 6 5 100 7 6 100 7 7 0 7 800 600 400 200 0 800 600 400 200 0 ideal 0 1 2 3 4 5 6 8 0 1 2 3 4 5 6 8
Example 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);