Image Enhancement in Spatial Domain (Chapter 3) Yun Q. Shi shi@njit.edu Fall 11 Mask/Neighborhood Processing ECE643 2 1
Point Processing ECE643 3 Image Negatives S = (L 1) - r (3.2-1) Point processing ECE643 4 2
ECE643 5 Log Transformations s = c log(1 + r) (3.2-2) ECE643 6 3
Power-Law (Gamma) Transformations s = c r γ (3.2-3) ECE643 7 Gamma Correction s = c r γ (3.2-3) ECE643 8 4
Power-Law (Gamma) Transformations s = c r γ (3.2-3) ECE643 9 Power-Law (Gamma) Transformations s = c r γ (3.2-3) ECE643 10 5
Piecewise-Linear Transformation Functions Contrast stretching ECE643 11 Piecewise-Linear Transformation Functions Intensity-level slicing ECE643 12 6
Piecewise-Linear Transformation Functions Intensity-level slicing ECE643 13 Piecewise-Linear Transformation Functions Bit-plane slicing ECE643 14 7
Piecewise-Linear Transformation Functions Bit-plane slicing ECE643 15 Piecewise-Linear Transformation Functions Bit-plane slicing ECE643 16 8
Definition of Histogram The histogram of a digital image having intensity levels [0,L-1] is h(r k )=n k, where r k is the k th intensity value and n k the number of pixels in the image assuming intensity r k. Normalization of histogram: h(r k )/MN (M N is the total number of pixels) Histogram reflects important information about the image. How do gray levels distributed in the image? Still, not one-to-one Important basis for numerous image processing techniques. ECE643 17 Fig. 3.16 Four basic image types: Dark, light, low contract, high contrast, and their corresponding histogram ECE643 18 9
Histogram Equalization Consider for a moment a continuous image, r(x,y), simply r A transform of r as follows: s = T(r), 0 r 1 T is strictly monotonically increasing, hence a one-to-one mapping Then, according to probability theory, we have p s (s) = p r (r) dr/ds If the function T is the CDF of r and is strictly monotonically increasing, then dr/ds = 1/p r (r) according to probability theory, hence p s (s) = 1 This is called histogram equalization. ECE643 19 Histogram Equalization T(r) is non-decreasing T(r) is monotonically increasing ECE643 20 10
Histogram Equalization Analogue case: histogram is exactly equalized ECE643 21 Histogram Equalization: One Example ECE643 22 11
Histogram Equalization: One Example ECE643 23 ECE643 24 12
Histogram Equalization ECE643 25 Histogram Specification Histogram equalization is only one way of manipulating histogram Sometimes, it does not work well Example 3.9 (Figures 3.23 and 3.24) next 2 slides Hence, we would like to work on histogram specification r(x,y): given image having its histogram p(r) z(x,y): desired image with histogram p(z) ECE643 26 13
ECE643 27 ECE643 28 14
ECE643 29 Histogram Specification For given r(x,y), we can do histogram equalization, end up with s(x,y) such that p(s) = CDF of r = T(r). For desired z(x,y), also do histogram equalization, end up with v(x,y) and p(v)=cdf of z = G(z). Note that both s and v are roughly uniformly distributed. Hence, we have z = G -1 [T(r)] For discrete case, we use mapping. ECE643 30 15
Histogram Specification Example 3.8 (continuation of Example 3.5) First, equalization of r and end up with s = T(r) Then, equalization of z, end up with v = G(z) Note that both s and v are (roughly) uniform distributed. Hence, we have z = G -1 [T(r)] This is discrete case, we use mapping. ECE643 31 Histogram Specification Some detail is as follows ECE643 32 16
Histogram Specification ECE643 33 ECE643 34 17
Histogram Specification Done ECE643 35 What is shown in text (3 rd edition) ECE643 36 18
ECE643 37 ECE643 38 19
ECE643 39 Local Histogram Processing Discussed above is Global histogram processing Transformation is based on global histogram Sometimes, this does not work effectively Example 3.10 (Fig. 3.26, the next slide) Hence, we sometimes need local histogram processing - Based on local histogram ECE643 40 20
ECE643 41 Histogram Statistics for Image Enhancement r : intensity value (treated as a random variable) Range of r : [0, L-1] p(r i ) : pdf - normalized histogram n th central moment: µ n (r) = all i (r i - m) n p(r i ) Mean: m = all i r i p(r i ) measure of average intensity Variance: µ 2 (r) = all I (r i - m) 2 p(r i ) measure of contrast Sample mean: m = (1/(M N)) x y f(x,y) Sample variance: σ 2 = (1/(M N)) x y [f(x,y) - m] 2 Sample mean and sample variance always can be found. ECE643 42 21
SEM: Scanning electron microscope for processing refer to the next slide ECE643 43 Parameters used in Figure 3.27 S x,y : a 3x3 neighborhood m Sx,y, σ Sx,y : local mean and local standard deviation m Sx,y compared with M G (global mean) σ Sx,y compared with D G (global standard deviation) g(x,y)= E f(x,y) if m Sx,y k 0 M G & k 1 D G σ Sx,y k 2 D G = f(x,y) otherwise Parameters used in Figure 3.27: E = 4.0, k 0 = 0.4, k 1 = 0.02, k 2 = 0.4 ECE643 44 22
Window operation (filtering) ECE643 45 Window operation (filtering) g(x,y)=w(-1,-1)f(x-1,y-1)+w(-1,0)f(x-1,y)+ +w(0,1)f(x,y)+ +w(1,1)x(x+1,y+1) Spatial filter: linear vs. non-linear Linear spatial filtering: g(x,y) = s=-a to a t=-b to b w(s,t)f(x+s,y+t) where x and y are varied so that each pixel (x,y) in the image has been visited by the window center. ECE643 46 23
Correlation and Convolution ECE643 47 Correlation and Convolution Correlation: w(x,y) g(x,y)= s=-a to a t =-b to b w(s,t)f(x+s,y+t) f(x,y): image w(x,y): linear filter, size m n, m and n are odd numbers a = (m-1)/2, b = (n-1)/2 Convolution: w(x,y)*g(x,y)= s=-a to a t =-b to b w(s,t)f(x-s,y-t) Convolution/Correlation filter, mask, kernal ECE643 48 24
Correlation and Convolution ECE643 49 Vector representation of linear filtering R = k=1 to 9 w k z k = w T z w and z are 9-D vectors w: weights (filter coefficients) z: image intensities encompassed by the mask Normalization: dividing the w T z by the sum of all the nine weights. ECE643 50 25
Average filter (a LPF) R = (1/9) k=1 to 9 z k, i.e., w i = 1/9 for all i. This will lead to image smoothing. ECE643 51 Non-linear filtering Non-linear filtering is also possible. For example: maximum filter. There the maximum value among 9 pixel values is used to replace the central pixel value. Ordered filter will be discussed later. ECE643 52 26
Smoothing Spatial filtering ECE643 53 ECE643 54 27
Threshold = 25% of the highest intensity in (b) (c) shows the largest, brightest objects in image (a) ECE643 55 Order-Statistic Filters Non-linear filtering Median filter Able to remove impulse noise Often called salt-and-pepper noise 50 th percentile of a ranked set of numbers Maximum filter 100 th Minimum filter 0th ECE643 56 28
ECE643 57 Sharpening Spatial Filter 1 st order derivative of a 1-D function f(x) f/ x = f(x+1) f(x) (Suitable for edge detection) 2 nd order derivative of a 1-D function f(x) 2 f/ x 2 = f(x+1) + f(x-1) 2f(x) (Sensitive to change) In both cases, using difference to approximate differentiation. ECE643 58 29
ECE643 59 Laplacian Using 2 nd order derivative for image sharpening Laplacian 2 f (x,y)= 2 f/ x 2 + 2 f/ y 2 2 f/ x 2 = f(x+1,y) + f(x-1,y) 2f(x,y) 2 f/ y 2 = f(x,y+1) + f(x,y-1) 2f(x,y) 2 f (x,y) = f(x+1,y) + f(x-1,y) + f(x,y+1) + f(x,y-1) 4f(x,y) ECE643 60 30
ECE643 61 Recover background The Laplacian highlights intensity discontinuity and de-emphases regions with slowly varying intensities. Background can be recovered while still preserving the sharpening effect by adding the Lapalacian image to the original one: g(x,y) = f(x,y) + c[ 2 f (x,y)] C = 1 or -1 ECE643 62 31
ECE643 63 Gradient Using 1 st order derivative for image sharpening Gradiant f (x,y) = grad(f) = [g x g y ] T = [ f/ x f/ y] T Magnitude of gradient M(x,y) M(x,y) = mag( f) = [(g x ) 2 + g y ) 2 ] (1/2) Gradient image (each element is gradient) In DIP, M(x,y) = mag( f) g x + g y ECE643 64 32
ECE643 65 Gradient Using 1 st order derivative for image sharpening Roberts gradient M(x,y) = mag( f) z 9 - z 5 + z 8 - z 6 Sobel gradient M(x,y) = mag( f) (z 7 + 2z 8 + z 9 ) (z 1 + 2z 2 + z 3 ) + (z 3 + 2z 6 + z 9 ) (z 1 + 2z 4 + z 7 ) ECE643 66 33
ECE643 67 ECE643 68 34
ECE643 69 Illustration of Figure 3.43 Aim: To have more skeletal detail Utilize the Laplacian to highlight fine detail Utilize gradient to enhance prominent edges Use a smoothed version of the gradient image to mask the Laplacian image (hence removing noise in the background) Increase the dynamic range of intensity by using power law ECE643 70 35
Summary Image enhancement in spatial domain Two ways: point-wise and window-wise Smooth, noise removal Sharpening, edge enhancement ECE643 71 36