440 likes | 465 Views
Learn about pixel intensity processing, histogram processing, combining images, and more in CSCE 563 with Prof. Amr Goneid at the American University in Cairo.
E N D
Digital Image Processing&Pattern Analysis(CSCE 563)Intensity Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American University in Cairo
Intensity Transformations • Pixel Intensity Processing • Histogram Processing • Combining Images Prof. Amr Goneid, AUC
Pixel Intensity Processing • Point Processing • Gray Scale to Binary • Negative • Power Law Transformation • Contrast Stretching • Compression of Dynamic Range • Gray Level Slicing Prof. Amr Goneid, AUC
Point Processing • Local Processing: g(x,y) = T[f(x,y)] T = Operator on Locality (neighborhood) of (x,y) e.g. 3 x 3 T [ ] (8-neighborhood) • Point Processing: For 1 x 1 we have Point Processing S = T[r] = T[ ] S = New Intensity, r = Old Intensity p Prof. Amr Goneid, AUC
Gray scale to Binary s = T(r,a) = 0 for r < a, 1 otherwise Prof. Amr Goneid, AUC
Negative (Image Complement) s =T(r) = 1-r The MATLAB function: g = imcomplement(f) s 1 0 1 r Prof. Amr Goneid, AUC
Power Law Transformation • Has the form: • The MATLAB function g = imadjust (f, [low-in high-in], [low-out high-out], gamma) Prof. Amr Goneid, AUC
Power Law Transformation • Example: • g = imadjust (f, [0 1], [1 0]); equivalent to: g = imcomplement (f); • g = imadjust (f, [0.3 0.7], [0.2 1.0]); Prof. Amr Goneid, AUC
Contrast Stretching Low contrast images do not make full use of the dynamic range of grey levels. In this case the intensities are confined to a narrow range rmin < r < rmax. We can use a point transformation s = T(r) to stretch the range to smin < s < smax Prof. Amr Goneid, AUC
Contrast Stretching r = old intensity, s = new intensity Slope = s/ r > 1 produces contrast stretching. = [(smax– smin)/(rmax– rmin)] Hence, s =T(r) = (r – rmin) + smin s s r r Prof. Amr Goneid, AUC
Contrast Stretching Example rmin = 0.0 , rmax = 0.3 smin = 0.0 , smax = 1.0 Prof. Amr Goneid, AUC
Contrast Stretching Function • The function compresses the input • levels lower than m into a narrow • range of dark levels in the output image. • Similarly, it compresses intensities • above m into a narrow band of light • levels in the output. • The result is an image of higher contrast. Prof. Amr Goneid, AUC
Contrast Stretching Function Summer 2009 The lena image on the right has been obtained by: load lena; m = 0.5; E = 0.5; g = 1./(1+(m./(double(f)+eps)).^E); gs = im2uint8(mat2gray(g)); imshow(gs); Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 13
Contrast Stretching Function Summer 2009 In the limiting case it produces a binary image. Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 14
Compression of Dynamic Range Map r = {0,D} to s = {0,L-1} where D >> L-1 s = T(r) = c log(1 + r ) c = (L-1)/log(1+D) e.g. compression from 256 gray levels to 16 gray levels. Summer 2009 Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 15
Gray Level Slicing s Examples: • S = T(r) = {1 for A<r<B ; c otherwise} • S = T(r) = {1 for r>A; r otherwise} 1 c 0 A B 1 r s 1 A 0 1 r Prof. Amr Goneid, AUC
Gray Level Slicing Example S = T(r) = {1 for r>0.6; r otherwise} Prof. Amr Goneid, AUC
Histogram Processing Abad contrast image (F) can be enhanced to an image G by transforming every pixel intensity fij to another intensity gij using a method called Histogram Equalization Prof. Amr Goneid, AUC
Histogram Processing • PDF and CDF • Histogram Equalization (Theory) • Histogram Equalization (Practice) • Histogram Specification Prof. Amr Goneid, AUC
Probability Density Function (PDF) • Suppose the gray levels r are normalized such that 0 < r< 1.0 • pr (r) dr = probability of intensity taking a value between r and r+dr. • A plot of pr (r) against riscalled the PDF of the image. • The PDF is normalized: Prof. Amr Goneid, AUC
Cumulative Distribution Function (CDF) • The CDF = the probability of having values less than r • For a uniform PDF, ps (s) = 1 and CDF = s (i.e. CDF is Linear) Uniform cdf Prof. Amr Goneid, AUC
Histogram Equalization (Theory) Mapping r into s such that ps (s) is uniform P(s) P(r) Too Bright Too Dark Bad Contrast Uniform High Contrast r s Prof. Amr Goneid, AUC
How? • Gray level r {0,1} transformed to s = T(r) {0,1} • T(r) is single valued and monotonically increasing • To find T(r), force the two CDF’s to be the same: CDF(r) = CDF(s) = s • Then solve to find s in terms of r Prof. Amr Goneid, AUC
Example 2 0 1 Prof. Amr Goneid, AUC
Will s have a uniform distribution? Prof. Amr Goneid, AUC
Histogram Equalization (Practice) • In practice, gray levels are discrete (k = 0 .. L-1) • A histogram is an array whose element nk = no. of pixels with gray level k (k = 0 is black, k = L-1 is white). • A histogram is a plot of nk vs rke.g. for L = 256 • In MATLAB n =imhist(I,256) Prof. Amr Goneid, AUC
Histogram Equalization (Practice) • Algorithm to build histogram for an image with N rows and M columns (Ntot = NM pixels): Prof. Amr Goneid, AUC
Histogram EqualizationAlgorithm (1) The histogram is used in the following algorithm: Prof. Amr Goneid, AUC
Histogram EqualizationAlgorithm (2) A better algorithm first builds a Cumulative array: Prof. Amr Goneid, AUC
Histogram EqualizationSummary of Total Complexity Algorithm (1): Algorithm (2): Prof. Amr Goneid, AUC
Histogram EqualizationNumerical Example L = 256 gray levels Algorithm (1): Algorithm (2): Prof. Amr Goneid, AUC
Histogram Equalization (Practice) If N = total no. of pixels = numel (I), then the PDF of input image is Pr(rk) = n(k)/N Summer 2009 Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 32
Practical ExamplesFrom:http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip.html Original Contrast Stretched Histogram Equalized Prof. Amr Goneid, AUC
Negative Ramp Prof. Amr Goneid, AUC
Liver Tissue Image Prof. Amr Goneid, AUC
Girl Image Summer 2009 Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 36
Histogram Specification • How to Transform an image (A) with Pr(r) to an image (B) with specified Pz(z). • For the input image (A), the uniform variable s = T(r) = CDF(r) • For the output image (B), s = H(z) = CDF(z) • Hence z = H-1(s) = H-1(T(r)) • In MATLAB: g = histeq (f , HistB) Prof. Amr Goneid, AUC
Histogram Specification (Example) Image A has Pr(r) = 2(1-r) (-ve ramp over r {0,1}) Image Bhas Pz(z) = 2z (+ve ramp over z {0,1}) T(r) = CDF(r)= 1 – (1-r)2 H(z) = CDF(z) = z2 H-1(s) = sqrt(s) z = H-1(T(r)) = sqrt(T(r)) = sqrt {1 – (1-r)2} Summer 2009 Prof. Amr Goneid, AUC Prof. Amr Goneid, AUC 38
A Practical Example(-)ve To (+)ve Ramp Prof. Amr Goneid, AUC
Combining Images • Arithmetic Operations • Logical Operations Prof. Amr Goneid, AUC
Combining Images • By Arithmetic Operations: e.g. Addition & Subtraction: C = min (A + B , 1); C = max (A – B , 0); • By Logical operations(Binary Images): C = A & B Logical AND C = A | B Logical OR C = A xor B Logical Exclusive OR C = ~ A Logical NOT Prof. Amr Goneid, AUC
Example: Arithmetic • I=Image; RN = Random Noise; B=boundary I + RN + B RN - I Prof. Amr Goneid, AUC
Example: Logical Mask AND Image1 = Image2 Prof. Amr Goneid, AUC
Other ExamplesFrom: http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip.html Image (A) Image (B) ~ B A & (~ B) A & B A xor B A | B Prof. Amr Goneid, AUC