Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Image Processing & Pattern Analysis (CSCE 563) Intensity Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American.

Similar presentations


Presentation on theme: "Digital Image Processing & Pattern Analysis (CSCE 563) Intensity Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American."— Presentation transcript:

1 Digital Image Processing & Pattern Analysis (CSCE 563) Intensity Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American University in Cairo

2 Prof. Amr Goneid, AUC2 Intensity Transformations Pixel Intensity Processing Histogram Processing Combining Images

3 Prof. Amr Goneid, AUC3 Pixel Intensity Processing Point Processing Gray Scale to Binary Negative Power Law Transformation Contrast Stretching Compression of Dynamic Range Gray Level Slicing

4 Prof. Amr Goneid, AUC4 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

5 Prof. Amr Goneid, AUC5 Gray scale to Binary s = T(r,a) = 0 for r < a, 1 otherwise

6 Prof. Amr Goneid, AUC6 Negative (Image Complement) s =T(r) = 1-r The MATLAB function: g = imcomplement(f) 1 0 r 1 s

7 Power Law Transformation Has the form: The MATLAB function g = imadjust (f, [low-in high-in], [low-out high-out], gamma) Prof. Amr Goneid, AUC7

8 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, AUC8

9 9 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 r min < r < r max. We can use a point transformation s = T(r) to stretch the range to s min < s < s max

10 Prof. Amr Goneid, AUC10 Contrast Stretching r = old intensity, s = new intensity Slope  =  s/  r > 1 produces contrast stretching.  = [(s max – s min )/(r max – r min )] Hence, s =T(r) =  (r – r min ) + s min r s  r  s

11 Prof. Amr Goneid, AUC11 Contrast Stretching Example r min = 0.0, r max = 0.3 s min = 0.0, s max = 1.0

12 Contrast Stretching Function Prof. Amr Goneid, AUC12 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.

13 Contrast Stretching Function Summer 2009Prof. Amr Goneid, AUC13 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); 13Prof. Amr Goneid, AUC

14 Contrast Stretching Function Summer 2009Prof. Amr Goneid, AUC14 In the limiting case it produces a binary image. 14Prof. Amr Goneid, AUC

15 Summer 2009Prof. Amr Goneid, AUC15 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. 15Prof. Amr Goneid, AUC

16 16 Gray Level Slicing Examples: S = T(r) = {1 for A<r<B ; c otherwise} S = T(r) = {1 for r>A; r otherwise} s r s r 1 0 0 1 1 1 A AB c

17 Prof. Amr Goneid, AUC17 Gray Level Slicing Example S = T(r) = {1 for r>0.6; r otherwise}

18 Prof. Amr Goneid, AUC18 Histogram Processing A bad contrast image (F) can be enhanced to an image G by transforming every pixel intensity f ij to another intensity g ij using a method called Histogram Equalization

19 Prof. Amr Goneid, AUC19 Histogram Processing PDF and CDF Histogram Equalization (Theory) Histogram Equalization (Practice) Histogram Specification

20 Prof. Amr Goneid, AUC20 Probability Density Function (PDF) Suppose the gray levels r are normalized such that 0 < r < 1.0 p r (r) dr = probability of intensity taking a value between r and r+dr. A plot of p r (r) against r is called the PDF of the image. The PDF is normalized:

21 Prof. Amr Goneid, AUC21 Cumulative Distribution Function (CDF) The CDF = the probability of having values less than r For a uniform PDF, p s (s) = 1 and CDF = s (i.e. CDF is Linear) Uniform cdf

22 Prof. Amr Goneid, AUC22 Histogram Equalization (Theory) Too Dark Bad Contrast Too Bright P(r)P(r) r Uniform High Contrast P(s)P(s) s Mapping r into s such that p s (s) is uniform

23 Prof. Amr Goneid, AUC23 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

24 Prof. Amr Goneid, AUC24 Example 2 0 1

25 Prof. Amr Goneid, AUC25 Will s have a uniform distribution?

26 Prof. Amr Goneid, AUC26 Histogram Equalization (Practice) In practice, gray levels are discrete (k = 0.. L-1) A histogram is an array whose element n k = no. of pixels with gray level k (k = 0 is black, k = L-1 is white). A histogram is a plot of n k vs r k e.g. for L = 256 In MATLAB n = imhist(I,256)

27 Prof. Amr Goneid, AUC27 Histogram Equalization (Practice) Algorithm to build histogram for an image with N rows and M columns (N tot = NM pixels):

28 Prof. Amr Goneid, AUC28 Histogram Equalization Algorithm (1) The histogram is used in the following algorithm:

29 Prof. Amr Goneid, AUC29 Histogram Equalization Algorithm (2) A better algorithm first builds a Cumulative array:

30 Prof. Amr Goneid, AUC30 Histogram Equalization Summary of Total Complexity Algorithm (1): Algorithm (2):

31 Prof. Amr Goneid, AUC31 Histogram Equalization Numerical Example L = 256 gray levels Algorithm (1): Algorithm (2):

32 Summer 2009Prof. Amr Goneid, AUC32 Histogram Equalization (Practice) If N = total no. of pixels = numel (I), then the PDF of input image is P r (r k ) = n(k)/N 32Prof. Amr Goneid, AUC

33 33 Practical Examples From: http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip.html OriginalContrast Stretched Histogram Equalized

34 Prof. Amr Goneid, AUC34 Negative Ramp

35 Prof. Amr Goneid, AUC35 Liver Tissue Image

36 Summer 2009Prof. Amr Goneid, AUC36 Girl Image 36Prof. Amr Goneid, AUC

37 37 Histogram Specification How to Transform an image (A) with P r (r) to an image (B) with specified P z (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)

38 Summer 2009Prof. Amr Goneid, AUC38 Histogram Specification (Example) Image A has P r (r) = 2(1-r) (-ve ramp over r {0,1}) Image B has P z (z) = 2z (+ve ramp over z {0,1}) T(r) = CDF(r)= 1 – (1-r) 2 H(z) = CDF(z) = z 2 H -1 (s) = sqrt(s) z = H -1 (T(r)) = sqrt(T(r)) = sqrt { 1 – (1-r) 2 } 38Prof. Amr Goneid, AUC

39 39 A Practical Example (-)ve To (+)ve Ramp

40 Prof. Amr Goneid, AUC40 Combining Images Arithmetic Operations Logical Operations

41 Prof. Amr Goneid, AUC41 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 & BLogical AND C = A | BLogical OR C = A xor BLogical Exclusive OR C = ~ ALogical NOT

42 Prof. Amr Goneid, AUC42 Example: Arithmetic I=Image; RN = Random Noise; B=boundary I + RN + BRN - I

43 Prof. Amr Goneid, AUC43 Example: Logical Mask AND Image1 = Image2

44 Prof. Amr Goneid, AUC44 Other Examples From: http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip.html Image (A) Image (B) ~ B A | B A & BA xor B A & (~ B)


Download ppt "Digital Image Processing & Pattern Analysis (CSCE 563) Intensity Transformations Prof. Amr Goneid Department of Computer Science & Engineering The American."

Similar presentations


Ads by Google