Chapter 3 Image Enhancement Domain Background Some Basic Gray Level Transformations Histogram Processing Enhancement Using Arithmetic/Logic Operations Basics of Spatial Filtering Smoothing Spatial Filters Sharpening Spatial Filters Combining Spatial Enhancement Methods in the Spatial Background masks filters, kernels, templates windows Spatial domain processes g ( x, y ) T [ f ( x, y )] where f ( x, y ) is the input image, g ( x, y ) is the processed image, and T is an operator on f , defined over some neighborhood of ( x, y ) . T can operate on a set of input images, such as performing the pixel-by-pixel sum of K images for noise reduction. Point processing A gray-level (also called an intensity or mapping) transformation function s T (r ) Contrast stretching, Thresholding function Some Basic Gray Level Transformations Image Negatives The negative of an image with gray levels in the range [0, L 1] is obtained by using the negative transformation shown in Fig. 3.3, which is given by the expression s L 1 r Log Transformations The general form of the log transformation shown in Fig. 3.3 is s c log ( 1 r) Power-Law Transformations Power-law transformations have the basic form s cr Piecewise-Linear Transformation Functions Contrast stretching Gray-level slicing Bit-plane slicing Histogram Processing The histogram of a digital image with gray levels in the range [0, L 1] is a discrete function h(rk ) nk , where rk is the kth gray level and nk is the number of pixels in the image having gray level rk . The right side of the figure shows the histograms corresponding to these images. The horizontal axis of each histogram plot corresponds to gray level values, rk . The vertical axis corresponds to values of h(rk ) nk or p(rk ) nk / n if the values are normalized. Histogram Equalization s T (r ) 0 r 1 (a) T (r ) is single-valued and monotonically increasing in the interval 0 r 1 ; and (b) 0 T (r ) 1 for 0 < r < 1. Let pr (r ) and p s (s) denote the probability density functions of random variables r and s, respectively dr p s ( s ) pr ( r ) ds A transformation function of particular importance in image processing has the form r s T ( r ) pr ( w)dw 0 We find p s (s) as a uniform probability function by applying ds dT (r ) d r pr ( w)dw pr (r ) dr dr dr 0 p s ( s ) pr ( r ) dr 1 pr ( r ) 1 ds pr ( r ) 0 s 1 For discrete values, The probability of occurrence of gray level rk in an image is approximated by n p r (rk ) k k 0,1,2,, L 1 n The discrete version of the transformation function is given as k k n j sk T (rk ) pr (rj ) k 0,1,2,, L 1 j 0 j 0 n Histogram Matching (Specification) Development of the method r s T ( r ) pr ( w)dw 0 z G( z ) pz (t )dt s 0 z G 1 ( s) G 1 (T (r )) k k nj j 0 n sk T (rk ) pr (rj ) j 0 k vk G ( z k ) p z ( z i ) s k k 0,1,2,, L 1 k 0,1,2,, L 1 i 0 z k G 1 ( sk ) k 0,1,2,, L 1 (G( zˆ) sk ) 0 k 0,1,2,, L 1 Implementation The procedure we have just developed for histogram matching may be summarized as follows: 1. Obtain the histogram of the given image. k k n j s T ( r ) p ( r ) k 0,1,2,, L 1 to precompute a mapped k k r j 2. Use n j 0 j 0 level sk for each level rk . 3. Obtain the transformation function G from the given pz (z) using k vk G ( z k ) p z ( z i ) s k i 0 k 0,1,2,, L 1 . 4. Precompute zk for each value of sk , where z k zˆ is the smallest integer such that (G( zˆ) sk ) 0 k 0,1,2,, L 1 . 5. For each pixel in the original image, if the value of that pixel is rk , map this value to its corresponding level sk ; then map level sk into the final level zk . Use the precomputed values from Steps (2) and (4) for these mappings. Local Enhancement Use of Histogram Statistics for Image Enhancement Global mean and variance L 1 n (r ) (ri m) n p(ri ) i 0 L 1 m ri p ( ri ) i 0 L 1 (r ) 2 (r ) (ri m) 2 p(ri ) 2 i 0 Local mean and variance mS xy S2 xy r s ,t ( s ,t )S xy [ r ( s ,t )S xy s ,t p(rs ,t ) mS xy ] p(rs ,t ) Summary of the enhancement method E f ( x, y ) if mSxy k0 M G and k1DG Sxy k1DG g ( x, y ) otherwise f ( x, y ) where E , k0 , k1 , and k2 are specified parameters; M G is the global mean of the input image; and DG is its global standard deviation. E 4.0 , k0 0.4 , k1 0.02 , and k2 0.4 Enhancement Using Arithmetic/Logic Operations Image Subtraction g ( x , y ) f ( x , y ) h ( x, y ) A few comments on implementation The values in a difference image can range from a minimum of -255 to a maximum of 255 One method is to add 255 to every pixel and then divide by 2 The other method, at first, the value of the minimum difference is obtained and its negative added to all the pixels in the difference image. Then, all the pixels in the image are scaled to the interval [0, 255] by multiplying each pixel by the quantity 255/Max, where Max is the maximum pixel value in the modified difference image Image Averaging g ( x, y ) f ( x , y ) ( x , y ) 1 K g ( x, y ) g i ( x, y ) K i 1 E{g ( x, y )} f ( x, y ) g2 ( x , y ) g ( x, y ) 1 2 ( x, y ) K 1 ( x, y ) K Basics of Spatial Filtering R w(1,1) f ( x 1, y 1) w(1,0) f ( x 1, y ) w(0,0) f ( x, y ) w(1,0) f ( x 1, y ) w(1,1) f ( x 1, y 1) g ( x, y ) a b w(s, t ) f ( x s, y t ) s a t b 9 R w1 z1 w2 z 2 w9 z9 wi zi i 1 mn R w1 z1 w2 z 2 wmn z mn wi zi i 1 Smoothing Spatial Filters Smoothing Linear Filters 1 9 R zi 9 i 1 a g ( x, y ) b w(s, t ) f ( x s, y t ) s a t b a b w(s, t ) s a t b Order-Statistics Filters Median filter Median filters are particularly effective in the presence of impulse noise, also called salt-and-pepper noise Max filter Min filter Sharpening Spatial Filters Foundation f f ( x 1) f ( x) x 2 f f ( x 1) f ( x 1) 2 f ( x) x 2 Use of Second Derivatives for Enhancement-The Laplacian 2 f 2 f f 2 2 x y 2 2 f f ( x 1, y ) f ( x 1, y ) 2 f ( x, y ) x 2 2 f f ( x, y 1) f ( x, y 1) 2 f ( x, y ) y 2 f [ f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)] 4 f ( x, y ) f ( x, y ) 2 f ( x, y ) if the center coefficien t of the Laplacian mask is negative g ( x, y ) 2 f ( x, y ) f ( x, y ) if the center coefficien t of the Laplacian mask is positive (3.7-5) Simplifications g ( x, y ) f ( x, y ) [ f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)] 4 f ( x, y ) 5 f ( x, y ) [ f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) Unsharp masking and high-boost filtering f s ( x , y ) f ( x, y ) f ( x , y ) where f s ( x, y) denotes the sharpened image obtained by unsharp masking, and f ( x, y ) is a blurred version of f ( x, y ) High-boost filtering f hb ( x, y ) Af ( x, y ) f ( x, y ) f hb ( x, y ) ( A 1) f ( x, y ) f ( x, y ) f ( x, y ) f hb ( x, y) ( A 1) f ( x, y) f s ( x, y) f hb Af ( x, y ) 2 f ( x, y ) if the center coefficien t of the Laplacian mask is negative 2 Af ( x, y ) f ( x, y ) if the center coefficien t of the Laplacian mask is positive Use of First Derivatives for Enhancement—The Gradient f G x x f f G y y f mag(f ) Gx2 Gy2 1/ 2 f Gx G y Gx ( z 9 z 5 ) G y ( z8 z 6 ) f ( z9 z5 ) 2 ( z8 z6 ) 2 1/ 2 Roberts cross-gradient operator f z9 z5 z8 z6 Sobel operator f ( z7 2z8 z9 ) ( z1 2z2 z3 ) ( z3 2z6 z9 ) ( z1 2z4 z7 ) Combining Spatial Enhancement Methods