Image Enhancement in Spatial Domain Histogram The histogram of a digital image with gray levels in the range [0,L-1] is a discrete function h ( rk ) = n k where rk is the kth gray level and nk is the number of pixels in the image having gray levels rk. Image Enhancement in Spatial Domain Histogram Image Enhancement in Spatial Domain Histogram Image Enhancement in Spatial Domain Histogram It is common practice to normalise a histogram by Dividing each of its values by the total number of Pixels in the image, denoted by n. Thus, a normalised histogram is given by nk p(rk ) = n for k = 0,1,…, L-1. p(rk) gives an estimate of the probability of occurrence of gray level rk. Image Enhancement in Spatial Domain Histogram Processing to extract and enhance the image intensity histogram Image Enhancement in Spatial Domain Histogram Equalisation s = T (r ) Image Enhancement in Spatial Domain Histogram Equalisation s = T (r ) dr p s ( s ) = pr ( r ) ds r s = T ( r ) = ∫ pr ( w)dw 0 Image Enhancement in Spatial Domain Histogram Equalisation 1 dr ps ( s ) = pr ( r ) = pr ( r ) ⋅ ds ds dr 1 1 = pr ( r ) ⋅ = pr ( r ) ⋅ =1 r pr ( r ) d ∫ pr ( w)dw 0 dr Image Enhancement in Spatial Domain Histogram Equalisation k sk = T (rk ) = ∑ pr (rj ) j =0 k nj j =0 n =∑ nj = the number of pixels with intensity rj n = the number of total pixels Image Enhancement in Spatial Domain Histogram Equalisation Intensity # pixels Accumulative Sum of Pr 0 20 20/100 = 0.2 1 5 (20+5)/100 = 0.25 2 25 (20+5+25)/100 = 0.5 3 10 (20+5+25+10)/100 = 0.6 4 15 (20+5+25+10+15)/100 = 0.75 5 5 (20+5+25+10+15+5)/100 = 0.8 6 10 (20+5+25+10+15+5+10)/100 = 0.9 7 10 (20+5+25+10+15+5+10+10)/100 = 1.0 Total 100 1.0 Image Enhancement in Spatial Domain Histogram Equalisation Intensity (r) No. of Pixels (nj) Acc Sum of Pr Output value Quantized Output (s) 0 20 0.2 0.2x7 = 1.4 1 1 5 0.25 0.25*7 = 1.75 2 2 25 0.5 0.5*7 = 3.5 3 3 10 0.6 0.6*7 = 4.2 4 4 15 0.75 0.75*7 = 5.25 5 5 5 0.8 0.8*7 = 5.6 6 6 10 0.9 0.9*7 = 6.3 6 7 10 1.0 1.0x7 = 7 7 Total 100 Image Enhancement in Spatial Domain Histogram Equalisation Image Enhancement in Spatial Domain Histogram Equalisation Image Enhancement in Spatial Domain Histogram Equalisation Image Enhancement in Spatial Domain Histogram Equalisation Image Enhancement in Spatial Domain Histogram Matching (Specification) original image after histogram equalisation Image Enhancement in Spatial Domain Histogram Matching (Specification) v = G(z) s = T(r) 2 1 3 z = G-1(v) 4 Image Enhancement in Spatial Domain Histogram Matching (Specification) r s = T ( r ) = ∫ pr ( w)dw 0 z v = G ( z ) = ∫ pz (u )du 0 −1 G T r → s →z Image Enhancement in Spatial Domain Histogram Matching (Specification) We assign Intensity (s) # pixels Intensity (z) # pixels 0 20 0 5 1 5 1 10 2 25 2 15 3 10 3 20 4 15 4 20 5 5 5 15 6 10 6 10 7 10 7 5 Total 100 Total 100 Image Enhancement in Spatial Domain Histogram Matching (Specification) r (nj) ΣPr s z (nj) ΣPz v 0 20 0.2 1 0 5 0.05 0 1 5 0.25 2 1 10 0.15 1 2 25 0.5 3 2 15 0.3 2 3 10 0.6 4 3 20 0.5 4 4 15 0.75 5 4 20 0.7 5 5 5 0.8 6 5 15 0.85 6 6 10 0.9 6 6 10 0.95 7 7 10 1.0 7 7 5 1.0 7 sk = T(rk) vk = G(zk) Image Enhancement in Spatial Domain Histogram Matching (Specification) r à s v à z s à v v z r z z # Pixels 1 0 0 0 1 0 0 1 2 1 1 1 2 1 20 2 3 2 2 2 2 2 30 3 4 4 3 3 3 3 10 4 5 5 4 4 4 4 15 5 6 6 5 5 5 5 15 6 6 7 6 6 5 6 10 7 7 7 7 7 6 7 0 r s 0 zk = G-1(vk) Image Enhancement in Spatial Domain Histogram Matching (Specification) Image Enhancement in Spatial Domain Histogram Matching (Specification) Original image After histogram equalization After histogram matching Image Enhancement in Spatial Domain Local Enhancement: Local Histogram Equalisation Original image After histogram equalisation After local histogram equalisation in 7x7 neighbourhood Image Enhancement in Spatial Domain Basic Statistics Let p(ri) denote the normalised histogram component corresponding to the ith value of r. The mean value (average gray level) of r is L −1 m = ∑ ri p (ri ) i =0 Image Enhancement in Spatial Domain Basic Statistics The nth moment of r about m is defined as L−1 µn (r) = ∑(ri − m)n p(r i ) i =0 µ 0 = 1, µ 1 = 0 The second moment is L−1 µ2 (r) = ∑(ri − m)2 p(r i ) = σ 2 (r) i =0 σ 2 (r) is the variance of r. σ (r) is the standard deviation of r. Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement Let (x,y) be the coordinates of a pixel in an image, let Sxy denote a neighbourhood (subimage) of specified size, centred at (x,y). The mean value mS xy of the pixel in S xy is computed using mS xy = ∑ ( s ,t )∈S xy rs ,t p (rs ,t ) where rs,t is the gray level at coordinates (s,t) in the neighbourhood, and p(rs,t) is the neighbourhood normalised histogram component corr. to that value of gray level. Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement The gray-level variance of the pixel in S xy is computed using σ 2 S xy = ∑ ( s ,t )∈S xy ( rs ,t − mS xy ) p (rs ,t ) 2 Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement E ⋅ f ( x, y ) when msxy ≤ k0 M G and k1DG ≤ σ sxy ≤ k2 DG g ( x, y ) = f ( x, y ) otherwise where MG is the global mean, and DG is the global standard deviation Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement Image Enhancement in Spatial Domain Histogram Statistics for Image Enhancement Image Enhancement in Spatial Domain Logic Operations AND OR Original image Image mask Region of Interest (ROI) Image Enhancement in Spatial Domain Arithmetic Operation: Subtraction Image Enhancement in Spatial Domain Arithmetic Operation: Subtraction Application: Mask mode radiography Image Enhancement in Spatial Domain Arithmetic Operation: Subtraction g ( x, y ) = f ( x, y ) − h ( x , y ) The difference image g(x,y) may be negative. There are two ways to solve this: 1. Add 255 to every pixel and then divide by 2. 2. Find the value of the minimum difference and add its negative to every pixel. Then find the maximum pixel value (Max) in the modified difference image and multiply each pixel by 255/Max. Image Enhancement in Spatial Domain Arithmetic Operation: Averaging g ( x, y ) = f ( x, y ) + η ( x , y ) (noise) } Image averaging 1 g ( x, y ) = K K ∑ g ( x, y ) i =1 i Image Enhancement in Spatial Domain Arithmetic Operation: Averaging Image Enhancement in Spatial Domain Spatial Filtering Image Enhancement in Spatial Domain Spatial Filtering filter = mask = kernel = template = window The values in a filter subimage are called coefficients. Image Enhancement in Spatial Domain Spatial Filtering 9 R = ∑ wi zi i =1 Image Enhancement in Spatial Domain Spatial Filtering Pixels at boundary • accept a smaller filtered image • padding by replicating rows or columns • padding by adding rows and columns of 0’s (or other constant gray level) Image Enhancement in Spatial Domain Smoothing Spatial Filters 1. Blurring • remove small details in order to extract large objects in an image. • bridge small gaps in lines or curves. 2. Noise reduction Image Enhancement in Spatial Domain Smoothing Linear Filters sometimes called averaging filters or lowpass filters Examples average or box filter weighted average Image Enhancement in Spatial Domain Smoothing Linear Filters Image Enhancement in Spatial Domain Smoothing Linear Filters Image Enhancement in Spatial Domain Order-Statistics Filters subimage Statistic parameters: Mean, Median, Mode, Min, Max, etc. Moving window Output image Image Enhancement in Spatial Domain Order-Statistics Filters: median filter Image Enhancement in Spatial Domain Sharpening Spatial Filters to highlight or enhance fine detail in an image Applications • Medical imaging • Printing • Industrial inspection • Autonomous guidance in military systems Image Enhancement in Spatial Domain Sharpening Spatial Filters Image Enhancement in Spatial Domain Second Derivative Intensity profile p(x) 1 Edge 0.5 0 20 40 60 80 100 120 140 160 180 200 0.2 1st derivative dp dx 2nd derivative d2p dx 2 0.1 0 0 50 100 150 200 0 50 100 150 200 0.05 0 -0.05 Image Enhancement in Spatial Domain Second Derivative 1.5 1 0.5 p(x) 0 -0.5 0 50 100 150 200 0 50 100 150 200 1.5 1 d2p p( x ) − 10 2 dx 0.5 0 -0.5 Image Enhancement in Spatial Domain Second Derivative Before sharpening p(x) After sharpening d2p p ( x ) − 10 2 dx Image Enhancement in Spatial Domain Second Derivative – the Laplacian The Laplacian of f(x,y) is defined as ∂ f ∂ f ∇ f = 2 + 2 ∂x ∂y 2 2 2 Image Enhancement in Spatial Domain Second Derivative – the Laplacian ∂ f = f (x +1, y) + f (x −1, y) − 2 f (x, y) 2 ∂x 2 ∂ f = f (x, y +1) + f (x, y −1) − 2 f (x, y) 2 ∂y 2 ∇2 f = f (x +1, y) + f (x −1, y) + f (x, y +1) + f (x, y −1) − 4 f (x, y) Isotropic filters are rotational invariant. Image Enhancement in Spatial Domain Second Derivative – the Laplacian Image Enhancement in Spatial Domain Second Derivative – the Laplacian f ∇2 f scaled ∇ f 2 f − ∇2 f Image Enhancement in Spatial Domain Second Derivative – the Laplacian f ( x, y ) − ∇ 2 f ( x, y ) g ( x, y ) = 2 f ( x , y ) + ∇ f ( x, y ) if the center coefficient of the Laplacian mask is negative if the center coefficient of the Laplacian mask is positive Image Enhancement in Spatial Domain Second Derivative – the Laplacian Image Enhancement in Spatial Domain Unsharp Masking fs (x, y) = f (x, y) − fb (x, y) fs(x,y) is the sharped image. fb(x,y) is a blurred version of f(x,y). Image Enhancement in Spatial Domain High-boost Filtering fhb (x, y) = Af (x, y) − fb (x, y) A≥1 fs(x,y) is the high-boost image. fb(x,y) is a blurred version of f(x,y). Image Enhancement in Spatial Domain High-boost Filtering f hb ( x, y ) = Af ( x, y ) − f b ( x, y ) = ( A − 1) f ( x, y ) + f ( x, y ) − fb ( x, y ) = ( A − 1) f ( x, y ) + f s ( x, y ) Af ( x, y ) − ∇ 2 f ( x, y ) f hb ( x, y ) = 2 Af ( x , y ) + ∇ f ( x, y ) if the center coefficient of the Laplacian mask is negative if the center coefficient of the Laplacian mask is positive Image Enhancement in Spatial Domain High-boost Filtering Image Enhancement in Spatial Domain High-boost Filtering Image Enhancement in Spatial Domain First Derivative – The Gradient Gradient ∂f ∂x ∇f = ∂f ∂y ∂f 2 ∂f 2 ∇f = + ∂x ∂y ∂f ∂f ∇f ≈ + ∂x ∂y 1 2 Image Enhancement in Spatial Domain First Derivative – The Gradient Robert crossgradient operators Sobel operators Image Enhancement in Spatial Domain Sobel Operators -1 0 1 -2 0 2 -1 0 1 f -1 -2 -1 ∂f to compute ∂x ∂f ∂x 0 0 0 1 2 1 ∂f to compute ∂y ∂f ∂y Image Enhancement in Spatial Domain First Derivative – The Gradient f ∂f ∂y ∂f ∂x ∇f Image Enhancement in Spatial Domain First Derivative – The Gradient ∂f ∂f ∇f = + ∂x ∂y 2 2 Image Enhancement in Spatial Domain Combining Spatial Enhancement Methods Image Enhancement in Spatial Domain ∇ 2 f Methods Combining Spatial Enhancement ∇f B A D smooth - + Sharpening C (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. E Image Enhancement in Spatial Domain Combining Spatial Enhancement Methods C G E Power Law Tr. Σ F Multiplication A (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. H Image Enhancement in Spatial Domain Combining Spatial Enhancement Methods Original image Result Image Enhancement in Spatial Domain