Intensity Transformations and Spatial Filtering: WHICH ONE LOOKS BETTER? 3.1 Intensity Transformations and Spatial Filtering: WHICH ONE LOOKS BETTER? 3.2 1 Intensity Transformations and Spatial Filtering • Goal: Image enhancement seeks – tto improve i the th visual i l appearance off an image, i or – convert it to a form suited for analysis by a human or a machine. • Image enhancement does not, however, – seek to restore the image, nor – increase its information contents • Peculiarity: – actually, there is some evidence which suggests that a distorted image can be more pleasing than a perfect image! 3.3 Information Content • Suppose a source, e.g. an image generates a discrete set of independent messages (grey levels) rk, with probabilities pk, k=1,...,L. • Then the information associated with rk is defined as Ik =-log2 pk bits • Since the sum of pk’s is 1 and each pk ≤ 1, Ik is nonnegative. g • This definition also implies that the information conveyed is large when an unlikely message is generated. 3.4 2 Intensity Transformations and Spatial Filtering Major Problem in Image Enhancement: the h llackk off a generall standard d d off image i quality lit makes it very difficult to evaluate the performance of different IE schemes. Thus, Image Enhancement algorithms are mostly application-dependent, subjective and often adhoc hoc. Therefore, mostly subjective criteria are used in evaluating image enhancement algorithms. 3.5 Subjective Criteria Used in Image Enhancement A. Goodness scale: how good an image is Overall goodness scale l Group goodness scale Excellent (5) Best (7) Good (4) Well above average (6) Fair (3) Slightly above average (5) Poor (2) Average (4) Unsatisfactory (1) Slightly below average (3) B. Impairment scale: how bad the degradation is in an image • not noticeable (1) • just noticeable (2) • definitely noticeable but only slight impairment (3) • impairment acceptable (4) • somewhat objectionable (5) • definitely objectionable (6) • extremely objectionable (7) Well below average (2) Worst (1) the numbers in parenthesis indicate a numerical weight attached to the rating. 3.6 3 Intensity Transformations and Spatial Filtering Spacial Domain: g(x,y) = T[f(x,y)] f(x,y) is the original image, g(x,y) is the output image and T[.] is an operator on f defined over a neighborhood of (x,y). Special case: neighborhood size is 1 pixel Æ T[.] is called 3.7 intensity or mapping transformation function. Lack of contrast 3.8 4 Intensity Transformations and Spatial Filtering Contrast Stretching Poor contrast is the most common defect in images and is causedd by b reduced d d and/or d/ nonlinear li amplitude lit d range or poor lighting conditions. A typical contrast stretching transformation is shown below (examples are given later): v vc γ vb β va α u 0 L a b 3.9 Intensity Transformations and Spatial Filtering Contrast Stretching A special case of contrast stretching is illustrated above (bi-level output) and is called thresholding. 3.10 5 Intensity Transformations and Spatial Filtering Basic Grey Level Transformations s = T[r] 3.11 Intensity Transformations and Spatial Filtering Image Negative s = L -1 - r r is the input grey level, s is the output grey level and L-1 is the maximum value of r. 3.12 6 Intensity Transformations and Spatial Filtering Log Transformation s = c log(1+r) c is a constant and r ≥ 0. This transformation maps a narrow range of low gray-level input values into a wider range of output levels. USE: Expand values of dark pixels in an image while 3.13 compressing higher level values. Inverse log will do the opposite Intensity Transformations and Spatial Filtering Power-Law transformations s = crγ (c and γ are positive constants) 3.14 7 Intensity Transformations and Spatial Filtering Power-law Transformation: Gamma Correction 3.15 Intensity Transformations and Spatial Filtering Power-Law Transformation for MR Image Enhancement Magnetic Resonance (MR) image of a fractured human spine 3.16 8 Intensity Transformations and Spatial Filtering Power-Law Transformation for Aerial Image Original aerial image has a washed-out appearance, i.e. compression of grey levels is needed. 3.17 Intensity Transformations and Spatial Filtering Piecewise-Linear Transformations 1. Contrast S Stretching hi a scanning electron microscope image of pollen magnified 700 times. 3.18 9 Intensity Transformations and Spatial Filtering Piecewise-Linear Transformations 2. Level slicingg an input image result after applying transformation in (a). Applications: enhancing features, e.g. masses of water in satellite imagery 3.19 and enhancing flaws in X-ray images. Intensity Transformations and Spatial Filtering Piecewise-Linear Transformations, another example 10 Intensity Transformations and Spatial Filtering Piecewise-Linear Transformations •3. 3. Bit-plane Bit plane Slicing 3.21 Intensity Transformations and Spatial Filtering 3. Bit-plane Bit plane Slicing: example 1: 3.22 11 Intensity Transformations and Spatial Filtering 3.23 3. Bit-plane Slicing: Example 2: 12 Intensity Transformations and Spatial Filtering Histogram Processing Basic image types: dark light low-contrast high-contrast 3.25 Intensity Transformations and Spatial Filtering Histogram Processing Histogram processing re-scales an image so that the enhanced image histogram follows some desired form. The modification can take on many forms: – histogram equalization equalization, or – histogram shaping • e.g. exponential or hyperbolic histogram 3.26 13 Intensity Transformations and Spatial Filtering Histogram Equalization • To transfer the gray levels so that the histogram of the resulting image is equalized to be a constant: • The purpose: – to equally use all available gray levels; • This figure shows that for any given mapping function between the input and output images, the following holds: • i.e., the number of pixels mapped from x to y is unchanged. 3.27 Intensity Transformations and Spatial Filtering Histogram Equalization To equalize the histogram of the input image, we let p(y) be a constant. Assume that the gray levels are in the range of 0 and 1 (0<x<1, 0<y<1). Then we have: i.e., the mapping function for histogram equalization is: where is the cumulative probability distribution of the input image, which is monotonically non-decreasing function. 3.28 14 Intensity Transformations and Spatial Filtering Histogram Equalization • Histogram equalization is based on the following idea: – If p(x) is large, y=f(x) has a steep slope, dy will be wide, causing p(y) to be low; – If p(x) is small, y=f(x) has a shallow slope slope, dy will be narrow, causing p(y) to be high. 3.29 Intensity Transformations and Spatial Filtering Histogram Equalization For discrete gray levels, the gray level of the input takes one of the discrete values;; and the continuous mapping function: becomes discrete: where Pi is the probability for the gray level of any given pixel to be (0<i<L): 3.30 15 Intensity Transformations and Spatial Filtering Histogram Equalization • The resulting function is in the range converted to the gray levels ways: and it needs to be by one of the two following • where is the floor, or the integer part of a real number x, and adding 0.5 is for proper rounding. Note that while both conversions map to the highest gray level L - 1, the second conversion also maps to 0 to stretch the gray levels of the output image to occupy the entire dynamic range . 3.31 Intensity Transformations and Spatial Filtering Histogram Equalization Example: Assume the images have pixels in 8 gray levels. The following table shows the equalization process corresponding to the two conversion methods above: 0/7 790 0.19 0.19 1/7 0.19 0.19 0/7 0.19 0.19 1/7 1023 0.25 0.44 3/7 0.25 0.44 2/7 0.25 0.44 2/7 850 0.21 0.65 5/7 0.21 0.65 4/7 0.21 0.65 3/7 656 0.16 0.81 6/7 5/7 0.16 0.81 4/7 329 0.08 0.89 6/7 6/7 0.08 0.89 5/7 245 0.06 0.95 7/7 6/7 122 0.03 0.98 7/7 7/7 81 0.02 1.00 7/7 0.11 1.00 0.24 0.89 7/7 7/7 0.11 1.00 7/7 y1j=[y’(L-1)+0.5], y2j=[(y’-y’min)/(1-y’min) (L-1) +0.5], 3.32 16 Intensity Transformations and Spatial Filtering Histogram Equalization 3.33 Intensity Transformations and Spatial Filtering Histogram Equalization • In the following example, the histogram of a given image is equalized. li d Although Alth h the th resulting histogram may not look constant, but the cumulative histogram is a exact linear ramp indicating that the density histogram is indeed equalized. The density histogram is not guaranteed to be a constant because the pixels of the same gray level cannot be separated to satisfy a constant distribution. 3.34 17 Intensity Transformations and Spatial Filtering Histogram Equalization Programming Hints: Find histogram of given image: Build lookup table: Image Mapping: 3.35 Intensity Transformations and Spatial Filtering Histogram Equalization Histogram equalization produces an output image by point rescaling such that the histogram of the new image is uniform. uniform Assume an image R of size M=NxN. • Let H R ( j) = # pixels with value rj M • where j=1,2, ..., J. HR(j) is just the fractional number of pixels whose amplitude is quantized to reconstruction level rj. We want to produce an enhanced image S whose histogram (normalized) is H S (i ) = 1 K i = 1,2,..., K i.e. a histogram that is as flat as possible. 3.36 18 Intensity Transformations and Spatial Filtering Histogram Equalization The scaling algorithm: 1 compute the 1. h average value l off the h histogram. hi 2. starting at the lowest gray level of the original, combine pixels in the quantization bands until the sum is closest to the average. 3. Rescale all of these pixels to the first reconstruction l l at the level h midpoint id i off the h enhanced h d image i first fi quantization band. 4. Repeat for higher gray level values. 3.37 Intensity Transformations and Spatial Filtering Histogram Equalization Remark: 1 Hi 1. Histogram equalization li i works k best b on images i with ih details “hidden” in dark regions. 2. Good quality originals are usually degraded when their histograms are equalized. 3. Other histogram modifications are possible, ex. a useful one is called histogram hyperbolization. 3.38 19 Intensity Transformations and Spatial Filtering Histogram Equalization 4. However, a normalized image histogram is just an approximation of the image probability density function! Therefore, histogram modification is nothing thi but b t modification difi ti off the th underlying d l i pdf! df! E.g., in histogram equalization, the enhanced image is desired to have a uniform p.d.f. That is, if pr(r) is the pdf of the original image r, then the pdf ps(s) of the enhanced image s is uniform. This is not a difficult probability problem: Consider a random variable (RV) R with pdf pR(r) and cumulative distribution function (cdf) PR(r). Find a transformation T(.) such that the new RV S=T(R) is uniform, i.e., pS(s) is a uniform density. 3.39 Intensity Transformations and Spatial Filtering Histogram Equalization Stop/Resume Claim: S=T(R)= PR(r) will do it. Proof: r S = PR (r ) = ∫ p R (t ) dt 0 Let's find the cdf of S (PS(s)). PS ( s ) = Pr ob[ PR (r ) ≤ s ] = Pr ob[ R ≤ PR−1 ( s )] for 0 ≤ s ≤ 1. =∫ PR−1 ( s ) 0 pR (t ) dt = PR ( PR−1 ( s)) = s 3.40 20 Intensity Transformations and Spatial Filtering Histogram Equalization In discrete case, r S = PR (r ) = ∫ pR (t ) dt 0 becomes k k nj j =0 j =0 n sk = T (rk ) = ∑ pR (rj ) =∑ (*) , , , for k=0,1,...,L-1. 3.41 Intensity Transformations and Spatial Filtering Histogram Equalization any transformation such as plotted above can be used as a transformation provided that • it is single valued and monotonically increasing, and • it takes values in [0,1] for inputs in [0,1]. 3.42 21 Intensity Transformations and Spatial Filtering Histogram Equalization 3.43 Intensity Transformations and Spatial Filtering Histogram Equalization k k nj j =0 j =0 n sk = T (rk ) = ∑ pR (rj ) =∑ (*) 3.44 22 Intensity Transformations and Spatial Filtering 3.45 Intensity Transformations and Spatial Filtering Histogram Equalization Photo of the Mars moon Phobos and its higtogram g g 3.46 23 Intensity Transformations and Spatial Filtering Histogram Equalization 3.47 Intensity Transformations and Spatial Filtering 3.48 24 Intensity Transformations and Spatial Filtering Localized Histogram Equalization 3.49 25 Intensity Transformations and Spatial Filtering 3.51 Intensity Transformations and Spatial Filtering mS ( x , y ) σ S ( x, y ) (1, E ) ⎧E. f (x, y) if mS( x, y) < k0mG and k1σG < σS( x, y) < k2σG ⎫ g(x, y) = ⎨ ⎬ otherwise ⎩ f (x, y) ⎭ 3.52 26 Intensity Transformations and Spatial Filtering ⎧E. f (x, y) if mS( x, y) < k0mG and k1σG < σS( x, y) < k2σG ⎫ g(x, y) = ⎨ ⎬ otherwise ⎩ f (x, y) ⎭ 3.53 Intensity Transformations and Spatial Filtering Enhancement using logic operations AND OR 3.54 27 Intensity Transformations and Spatial Filtering Enhancement using arithmetic operations 3.55 Note: Fig. 3.14(a) is the original picture in 3rd ed. 28 Intensity Transformations and Spatial Filtering Enhancement using arithmetic operations 3.57 Intensity Transformations and Spatial Filtering Enhancement using spatial averaging operations When images are displayed (or printed), they often have suffered from noise and interferences from several sources including: – electrical sensor noise, – photographic grain noise, and – channel errors. These noise Th i effects ff t can usually ll be b removedd by b simple ad hoc “noise-cleaning” techniques applied to local neighborhoods of input pixels. 3.58 29 Intensity Transformations and Spatial Filtering Enhancement using spacial averaging operations Consider a noisy image: g ( x, y ) = f ( x, y ) + η ( x, y ) where the second term is noise which is uncorrelated with the input and has zero mean. Then, averaging K different noisy images: g (x, y) = 1 K K ∑ i=1 g i(x, y) produces an output image with E[ g ( x, y )] = f ( x, y ) and σ g2 = 1 2 ση K 3.59 Intensity Transformations and Spatial Filtering Enhancement using averaging operations original i i l result of aver 8 noisy images noisy image, image N(0,64 N(0 642) 16 noisy images 128 noisy images 64 noisy images 3.60 30 Intensity Transformations and Spatial Filtering K=8 K=16 K=64 notice how the noise variance is decreasing with i h increasing i i K. K K=128 3.61 Intensity Transformations and Spatial Filtering Each pixel u(m,n) is replaced by a weighted average of its neighbourhood pixels 3.62 31 Intensity Transformations and Spatial Filtering Linear Filtering M g ( x, y ) = N ∑ ∑ w(m, n) f ( x + m, y + n) m=− M n=− N M N ∑ ∑ w(m, n) m=− M n=− N where g(x,y) is the output image and f(x,y) is the input image. In the mask above, M=N=1. 3.63 Intensity Transformations and Spatial Filtering Spacial averaging operations Consider again a noisy image: g ( x, y ) = f ( x, y ) + η ini ( x, y ) where the second term is noise which is uncorrelated with the input and has zero mean. Let’s apply a local averaging filter (all weights are equal) with size K=(2M+1)x(2N+1): g ( x, y ) = 1 K ⎡1 ⎤ ∑ ∑ g ( x, y ) = ⎢ K ∑ ∑ f ( x, y ) ⎥ + η ⎣ ( x , y )∈W ( x , y )∈W ⎦ out ( x, y ) produces an output image with 2 σ out = 1 2 σ in K Therefore, if the input is constant over W, the SNR has improved by a factor of K!! 3.64 32 Intensity Transformations and Spatial Filtering 3.65 Intensity Transformations and Spatial Filtering original 3 x 3 mask 5 x 5 mask 9 x 9 mask 15 x 15 mask 35 x 35 mask 3.66 33 Intensity Transformations and Spatial Filtering Linear Filtering Example Image from the hubble space telescope in orbit around the Earth. Here, we want to blur the image in order to see large objects. 3.67 Intensity Transformations and Spatial Filtering Q: What happen when important details must be preserved or the noise is non-Gaussian? non Gaussian? A: may consider a number of techniques: – median and order statistics filtering, – sharpening spacial filters • directional di ti l filtering, filt i – unsharp masking – hybrid combinations 3.68 34 Intensity Transformations and Spatial Filtering Nonlinear Filtering Median or order statistics filters may perform much better in the presence of non-Gaussian noise (Nonlinear Signal Processing course!) 3.69 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters (subtract pixels from right to left) (subtract 1st derivative again from right to left) 3.70 35 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters First Order Derivative Second Order Derivatives • First order derivative – produces thicker edges – has stronger response to grey-level steps • Second order derivative – has a much stronger response to details – pproduces a double response p at stepp changes g in ggrey y level – has a stronger response to a line than to a step and to a point than to a line. • Conclusion – Second derivative is more useful to enhance image details 3.71 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters: Laplacian • Isotropic 2nd order derivative (Laplacian) ∇2 f = • In digital form: ∂2 f ∂2 f + ∂2 x2 ∂2 y2 ∂2 f = f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y ) ∂2x2 • in the x-direction and in the y-direction: ∂2 f = f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y ) ∂2 y2 • 2-D Laplacian: ∇2 f = ∂2 f ∂2 f + 2 2 2 2 ∂ x ∂ y • this can be implemented using the mask in the next slide 3.72 36 Intensity Transformations and Spatial Filtering isotropic for rotations in increments of 90° * 45° negatives of the above two masks 3.73 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters: Laplacian • Enhancement using Laplacian: ⎧ f ( x, y ) − ∇ 2 f ( x, y ) if the mask center coeff is negative g ( x, y ) = ⎨ 2 ⎩ f ( x, y ) + ∇ f ( x, y ) if the mask center coeff is positive 3.74 37 Intensity Transformations and Spatial Filtering image of the north pole of the moon result of filtering with the 45o mask Laplacian image scaled for display purpose enhanced image 3.75 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters: Laplacian • The previous expression : ⎧ f ( x, y ) − ∇ 2 f ( x, y ) if the mask center coeff is negative g ( x, y ) = ⎨ 2 ⎩ f ( x, y ) + ∇ f ( x, y ) if the mask center coeff is positive • The above two operations can be combined and thus simplified: g(x, y) = 5 f (x, y) −[ f (x +1, y) + f (x −1, y) + f (x, y +1) + f (x, y −1)] • This operation can be implemented using the mask in the next slide. 3.76 38 Intensity Transformations and Spatial Filtering 90° 45° results for the 90° SEM iimage results for the 45° Notice how much sharper it is! 3.77 Intensity Transformations and Spatial Filtering Laplacian with high-boost filtering gives better results if the original image is darker than desired see example in next slide. desired, slide 3.78 39 Intensity Transformations and Spatial Filtering -1 -1 -1 -1 8 -1 -1 -1 -1 b -11 -11 -11 -1 9.7 -1 -1 -1 -1 -1 -1 -1 -1 9 -1 -1 -1 -1 3.79 Intensity Transformations and Spatial Filtering Sharpening Spacial Filters: First Derivative, the Gradient • First derivatives are implemented using the magnitude of the gradient gradient. The gradient is given by: ⎡ ∂f ⎤ ⎡G x ⎤ ⎢ ∂x ⎥ ∇f = ⎢ ⎥ = ⎢ ∂f ⎥ ⎣⎢G y ⎦⎥ ⎢ ⎥ ⎣⎢ ∂y ⎦⎥ • The magnitude of the gradient is given by: ⎡⎛ ∂f ⎞ 2 ⎛ ∂f ⎞ 2 ⎤ ∇f = mag (∇f ) = [G x2 + G y2 ]1 / 2 = ⎢⎜ ⎟ + ⎜⎜ ⎟⎟ ⎥ ⎢⎣⎝ ∂x ⎠ ⎝ ∂y ⎠ ⎥⎦ 1/ 2 • note that components of the gradient are linear operators, but the magnitude is not! Also the partial derivatives are not isotropic, but the magnitude is! • The magnitude can be (for implementation reasons) approximated by: ∇f ≈ G x + G y 3.80 40 Intensity Transformations and Spatial Filtering f(x,y) } Roberts cross-gradient operator (2x2) ∇f ≈| z 9 − z 5 | + | z 8 − z 6 | } Gy Sobel operators (3x3) Gx 3.81 Intensity Transformations and Spatial Filtering 3.82 41 original original+ Laplacian Laplacian of origginal Intensity Transformations and Spatial Filtering Combining spatial enhancement methods •Single technique may not produce desirable results •Must thus devise a strategy for the given application at hand This application: nuclear whole body scan want to detect deseases, e.g. bone infection and tumors Sobel of orig Strategy: •use Laplacian to highlight details, •gradient to enhance edges, •grey-level trans. to increase dynamic range 3.83 Intensity Transformations and Spatial Filtering smoothed Sobel orig + mask Mask obtained by: (orig + Lap) x (smoothed Sobel) Fi l result Final l power law to orig. + mask 3.84 42 Digital Image Processing, 3rd ed. Gonzalez & Woods www.ImageProcessingPlace.com Chapter 3 Intensity Transformations & Spatial Filtering Self-study: Section 3.8. Using Fuzzy Techniques for Intensity Transformations and Spatial Filtering. © 1992–2008 R. C. Gonzalez & R. E. Woods 43