2.2 Image Enhancement - Histogram Processing & Spatial Domain(Smoothing & Sharping).pdf

Full Transcript

IMAGE PROCESSING UNIT 2: IMAGE ENHANCEMENT Spatial Domain:Histogram Processing & Smoothing and Sharpening Filters(Part 2) Compiled By Prof. Dharmesh Tank CE\IT Department, LDRP-ITR Histogram Proce...

IMAGE PROCESSING UNIT 2: IMAGE ENHANCEMENT Spatial Domain:Histogram Processing & Smoothing and Sharpening Filters(Part 2) Compiled By Prof. Dharmesh Tank CE\IT Department, LDRP-ITR Histogram Processing Histogram: It is a plot of frequency of occurrence of an event. An image histogram is a freq. of type of histogram that acts occurrence as a graphical representation of the tonal distribution in a digital image. It plots the number of pixels for each tonal value. By looking at the histogram for a specific image a viewer will 0 1 2 3 event be able to judge the entire tonal distribution at a glance. Histogram Processing  Histogram of images provide a global description of their appearance.  Enormous information is obtained.  It is a spatial domain technique.  Histogram of an image represents relative frequency of occurrence of various gray levels.  Histogram can be plotted in two ways: Histogram Processing  First Method:  X-axis has gray levels & Y-axis has No. of pixels in each gray levels. nk Gray No. of Pixels 40 Level (nk) 30 No. of Pixels 0 40 1 20 20 2 10 3 15 10 4 10 0 1 2 3 4 5 6 5 3 Gray Levels 6 2 Histogram Processing  Second Method:  X-axis has gray levels & Y-axis has probability of occurrence of gray levels. P(µk) = nk / n; where, µk – gray level nk – no. of pixels in kth gray level n – total number of pixels in an image No. of Pixels 1 Gray Level P(µk) (nk) 0.8 0 40 0.4 Prob. Of Occurrence 0.7 1 20 0.2 0.6 2 10 0.1 0.5 0.4 3 15 0.15 0.3 4 10 0.1 0.2 5 3 0.03 0.1 6 2 0.02 0 1 2 3 4 5 6 µk n = 100 1 Histogram Processing  Advantage of 2nd method: Maximum value plotted will always be 1.  White – 1, Black – 0.  Great deal of information can be obtained just by looking at histogram.  Types of Histograms: P(µk) P(µk) 0 rk 0 rk P(µk) P(µk) 0 rk 0 rk Histogram Processing  Advantage of 2nd method: Maximum value plotted will always be 1.  White – 1, Black – 0.  Great deal of information can be obtained just by looking at histogram.  Types of Histograms: P(µk) Dark Image P(µk) Bright Image 0 rk 0 rk P(µk) Low Contrast Image P(µk) Equalized Image 0 rk 0 rk Histogram Processing  The last graph represent the best image.  It is a high contrast image.  Our aim would be to transform the first 3 histograms into the 4th type.  In other words we try to increase the dynamic range of the image. Histogram Stretching 1) Linear stretching:  Here, we don’t alter the basic shape.  We use basic equation of a straight line having a slope. (Smax - Smin)/(rmax - rmin) Where, Smax – max gray level of output Smin – min gray level of output image rmax – max gray level of input image rmin – min gray level of input image 0 min max 0 min max Histogram Processing New slop transformation of Gray level S = T(r) = ((Smax - Smin)/(rmax - rmin))(r - rmin) + Smin Smax Smin rmin rmax Examples Example: 1) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 0 0 50 60 50 20 10 0 Ex. 1) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 0 0 50 60 50 20 10 0 Soln:- rmin = 2; rmax = 6; smin = 0; smax = 7; slope = ((smax – smin)/(rmax - rmin)) = ((7 - 0)/(6 - 2)) = 7 / 4 = 1.75. r (7 / 4)(r - 2) = S S = T(r) = ((Smax - Smin)/(rmax - rmin))(r - rmin) + Smin 2 0 =0 S = (7 / 4)(r - 2) + 0; 3 7/4 = 1.75 = 2 S = (7 / 4)(r - 2) 4 7/2 = 3.5 = 4 5 21/4 = 5.25 = 5 6 7 =7 Input Image Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 0 0 50 60 50 20 10 0 r S 2 0 Mapping table 3 2 4 4 5 5 6 7 Resultant Image Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 50 0 60 0 50 20 0 10 Solution: Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7 [0, 7]. Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 50 0 60 0 50 20 0 10 60 60 50 50 40 40 30 30 20 20 10 10 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 Example: 2) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7. Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 100 90 85 70 0 0 0 0 Ex. 2) Perform Histogram Stretching so that the new image has a dynamic range of 0 to 7. Gray Levels 0 1 2 3 4 5 6 7 No. of Pixels 100 0 90 0 0 85 0 70 Dynamic range increases BUT No. of pixels at each gray level remains constant. Histogram Equalization 2) Histogram Equalization: o Linear stretching is a good technique but not perfect since the shape remains the same. o Most of the time we need a flat histogram. o It can’t be achieved by Histogram Stretching. o Thus, new technique of Histogram Equalization came into use. o Perfect image is one where all gray levels have equal number of pixels. o Here, our objective is not only to spread the dynamic range but also to have equal pixels at all gray levels. Histogram Equalization nk Normal Histogram r nk Equalized Histogram nk Linearly Stretched Histogram S S Histogram Equalization o We have to search for a transform that converts any random histogram into flat histogram. o S = T(r) o We have to find ‘T’ which produces equal values in each gray levels. o The Transform should satisfy following 2 conditions: (i) T(r) must be single value & monotonically increasing in the interval, 0 ≤ r ≤ 1. (ii) 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1 0 ≤ S ≤ 1 for 0 ≤ r ≤ 1 Here, range of r is [0, 1] (Normalized range) instead of [0, 255]. These two conditions mean: 1) If T(r) is not single value: S T(r) S T(r) S2 S1 S1 r1 r2 r r1 r2 r fig. (a) fig. (b)  In fig.(a) r1 & r2 are mapped as single gray level i.e. S1.  Two different gray levels occupy same in modified image.  Big Drawback!  Hence, transformation has to be single value.  This preserves order from black to white.  A gray level transformation with single value and monotonically increasing is shown in fig.(b). 2) If condition (ii) is not satisfied then mapping will not be consistent with the allowed range of pixel value.  S will go beyond the valid range.  Since, the Transformation is single value & monotonically increasing, the inverse Transformation exists. r = T-1(S) ; 0 ≤ S ≤ 1  Gray levels for continuous variables can be characterized by their probability density Pr(r) & Ps(S).  From Probability theory, we know that,  If Pr(r) & Ps(S) are known & if T-1(S) satisfies condition (i) then the probability density of the transferred gray level is Ps(S) = [Pr(r) x (dr/ ds)] where r= T-1(S) ----(a) Prob. Density (Transformed Image) = Prob. Density (Original Image) x Inverse Slope of transformation  Now lets find a transform which would give us a flat histogram.  Cumulative Density Function (CDF) is preferred.  CDF is obtained by simply adding up all the PDF’s. S = T(r) 𝑟 S = න Pr(r) 𝑑𝑟 ; 0 ≤ r ≤ 1 0 differentiate w.r.t. r ds / dr = Pr(r) ---------(b) Equating eqn(a) & eqn(b), we get Ps(s) = 1 ; 0≤S≤1 i.e. Ps(s) = 1  A bad Histogram becomes a flat histogram when we find the CDF. Pr(r) Ps(s) 1 1 CDF Pr(r) dr 0 1 f 0 1 S Non-Uniform Function Uniform Function  NOTE: If ‘n’ is total no. of pixels in an image, then PDF is given by: Pr(rk) = nk / n; In frequency domain, 𝑟 S = T(r) = න Pr(rk) 𝑑𝑟 0 In discrete domain, 𝑟 Sk = T(rk) = ෍ Pr(rk) (CDF) 𝑘=0 Example: 1) Equalize the given histogram Gray Levels (r) 0 1 2 3 4 5 6 7 No. of Pixels(nk) 790 1023 850 656 329 245 122 81 nk 1000 900 800 700 600 500 400 300 200 100 0 1 2 3 4 5 6 7 r Gray Level No of Pixels (PDF) (CDF) (L-1)*Sk=7*Sk Round off (rk) (nk) Pr(rk)=nk/n Sk=∑Pr(rk) 0 790 0.19 0.19 1.33 1 1 1023 0.25 0.44 3.08 3 2 850 0.21 0.65 4.55 5 3 656 0.16 0.81 5.67 6 4 329 0.08 0.89 6.23 6 5 245 0.06 0.95 6.65 7 6 122 0.03 0.98 6.86 7 7 81 0.02 1 7 7 n = 4096 1 Equating Gray Levels to No. of Pixels: 0 -> 0 4 -> 0 1 -> 790 5 -> 850 2 -> 0 6 -> 985 3 -> 1023 7 -> 448 Total : 4096 Hence Verified!!! Solution Equalized Histogram: (Graph) Gray Levels (S) 0 1 2 3 4 5 6 7 No. of Pixels 0 790 0 1023 0 850 985 448 Total: 4096 nk 1000 900 800 700 600 500 400 300 200 100 0 1 2 3 4 5 6 7 r Problem 2) Equalize the given histogram Gray Levels (r) 0 1 2 3 4 5 6 7 No. of Pixels 100 90 50 20 0 0 0 0 nk 100 90 80 70 60 50 40 30 20 10 0 1 2 3 4 5 6 7 r Prob. 3) Equalize the above histogram twice. Gray Levels (r) 0 1 2 3 4 5 6 7 No. of Pixels 0 0 0 100 0 90 50 20 nk 100 90 80 70 60 50 40 30 20 10 0 1 2 3 4 5 6 7 r Prob. 3) Equalize the above histogram twice. Gray Levels (r) 0 1 2 3 No. of Pixels 70 20 7 3 nk 100 90 80 70 60 50 40 30 20 10 0 1 2 3 r Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 1 2 3 no. of 4 5 6 7 pixels 1 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 No. of Levels Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 1 2 3 4 5 6 7 8 9 10 11 0000 0001 0010 0011 12 13 14 15 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 1 2 3 4 5 6 7 8 9 10 11 0000 0001 0010 0011 12 13 14 15 0100 0101 0110 0111 1000 1001 1010 1011 0000 0000 0000 0000 1100 1101 1110 1111 0100 0100 0100 0100 1000 1000 1000 1000 1100 1100 1100 1100 Setting lower order bit plane to zero. Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 0 0 0 0 1 2 3 4 4 4 4 4 5 6 7 8 8 8 8 8 9 10 11 0000 0001 0010 0011 12 12 12 12 12 13 14 15 0100 0101 0110 0111 1000 1001 1010 1011 0000 0000 0000 0000 1100 1101 1110 1111 0100 0100 0100 0100 1000 1000 1000 1000 1100 1100 1100 1100 Setting lower order bit plane to zero. Prob. 1) What effect would setting to zero the lower order bit plane have on the histogram of an image shown? 0 0 0 0 0 1 2 3 4 4 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 12 12 12 12 13 14 15 0000 0000 0000 0000 4 0100 0100 0100 0100 no. of pixels 1000 1000 1000 1000 1100 1100 1100 1100 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 no. of levels Prob. 2) What effect would setting to zero the higher order bit plane has on the histogram of an image shown? Comment on the image. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Prob. 3) Given below is the slope transformation & the image. Draw the frequency tables for the original & the new image. Assume Imin=0, Imax = 7 2 3 4 2 5 5 2 4 I 3 6 3 5 Imax 6 3 5 5 Imin mmin mmax µ Enhancement using Arithmetic/Logic Operations  Performed on a pixel by pixel basis between two or more images  Logic Operations  AND  OR  NOT  Arithmetic Operations  Addition  Subtraction  Multiplication  Averaging Basic Arithmetic Operations Operation Definition ADD c=a+b SUB c=a-b MUL c=a*b DIV c=a/b LOG c = log(a) EXP c = exp(a) SQRT c = sqrt(a) TRIG. c = sin/cos/tan(a) INVERT c = (2B - 1) - a Logic Operations: AND&OR Arithmetic & Logic Operations Example 1 a b This excludes NOT(a) the logic operation NOT, which is performed on a.b a single image a+b Arithmetic Operations Example 2. = + = Arithmetic Operations: Image Subtraction  The difference between two images f(x, y) and h(x, y), expressed as  𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − ℎ(𝑥, 𝑦)  is obtained by computing the difference between all pairs of corresponding pixels from f and h. The key usefulness of subtraction is the enhancement of differences between images. Arithmetic Operations: Image Averaging  Consider an uncorrelated Original noise with zero average value then K=1 1 𝐾  𝑔ҧ 𝑥, 𝑦 = σ𝑖=1 𝑔𝑖 (𝑥, 𝑦) 𝐾  Average multiple pictures of the same scene to reduce noise K=8 K=16 K=64 K=128 Application K=8  Noise Reduction  Astronomy  Surveillance K=16  Background estimation K=64 K=128 Neighbourhood Pixels Processing: Basics of Spatial Filtering 7  Filtering refers to accepting(passing) or rejecting certain frequency components. This effectively smoothens or sharpens the image. E.g. Low pass filter, high pass filter, etc.  Some neighbourhood operations work with the values of the image pixels in the neighbourhood and the corresponding values of a subimage that has the same dimensions as the neighbourhood.  The subimage is called a filter, mask , kernel, template, or window.  With the first three terms being the most prevalent terminology.  The values in a filter subimage are referred to as coefficients, rather than pixels.  Spatial filters are more versatile as they are used in linear as well as non-linear filtering (Difficult in frequency domain). Spatial filtering  The process consists simply of moving the filter mask from point to point in an image. At each point (x, y), the response of the filter at that point is calculated using a predefined relationship.  For linear spatial filtering, the response is given by a sum of products of the filter coefficients and the corresponding image pixels in the area spanned by the filter mask.  Example: with a 3x3 mask Linear Spatial Filtering 3 x 3 Neighborhood / Mask / Window / Template:  The process consists of moving the filter (y - 1) y (y + 1) Y mask from pixel to w(-1,-1) w(-1,0) w(-1,1) pixel in an image. (x - f(x-1, y-1) f(x-1, y) f(x-1, y+1) 1)  At each pixel (x, y), the response is given w(0,-1) w(0,0) w(0,1) by a sum of x f(x, y-1) f(x, y) f(x, y+1) products of the filter coefficients and the corresponding w(1,-1) w(1,0) w(1,1) image pixels in the (x + f(x+1, y-1) f(x+1, y) f(x+1, area spanned by 1) y+1) the filter mask. X Continue… Ex 1: Use the following 3×3mask to perform the convolution process on the shaded pixels in the 5×5 image below. Write the filtered image. 0 1/6 0 30 40 50 70 90 40 50 80 60 100 1/6 1/3 1/6 35 255 70 0 120 0 1/6 0 30 45 80 100 130 40 50 90 125 140 3×3 mask 5×5 image Non-Linear Spatial Filtering  The operation also consists of moving the filter mask from pixel to pixel in an image.  The filtering operation is based conditionally on the values of the pixels in the neighbourhood, and they do not explicitly use coefficients in the sum-of-products manner.  For example, noise reduction can be achieved effectively with a nonlinear filter whose basic function is to compute the median Gray-level value in the neighbourhood in which the filter is located.  Computation of the median is a nonlinear operation. Correlation & Convolution Correlation & Convolution are two closely related concepts used in linear spatial filtering. Correlation: It is a process of moving a filter mask over an image & computing the sum of products at each location. Convolution: Here, the mechanics are same, except that the filter is first rotated by 180˚. Correlation & Convolution are function of displacement. Correlation & Convolution are exactly same if the filter mask is symmetric. 1D correlation and convolution of a filter with a discrete unit impulse is shown below. Correlation & Convolution Summarizing in equation form, we have that The Correlation of a filter w(x, y) of size mxn with an image f(x, y)is given by: The Convolution of w(x, y) and f(x, y) is given by: Example of Convolution Convolution kernel, ω Input Image, f 1 -1 -1 2 2 2 3 1 2 -1 2 1 3 3 1 1 1 2 2 1 2 Rotate 180o 1 3 2 2 1 1 1 -1 2 1 -1 -1 1 Convolution 1 1 1 2 2 2 3 -1 2 1 2 1 3 3 -1 -1 1 2 2 1 2 1 3 2 2 1 1 1 -1 4 2 1 2 2 3 5 -1 -2 -1 1 3 3 Output Image, g 2 2 1 2 1 3 2 2 Input Image, f Convolution 1 1 1 2 2 2 3 -1 2 1 2 1 3 3 -1 -1 1 2 2 1 2 1 3 2 2 1 1 1 -2 4 2 3 5 4 Output -2 -1 3 3 Image, g 2 2 1 2 1 3 2 2 Input Image, f Convolution 1 1 1 2 2 2 3 -1 2 1 2 1 3 3 -1 -1 1 2 2 1 2 1 3 2 2 1 1 1 2 -2 4 3 5 4 4 Output 2 -1 -3 3 Image, g 2 2 1 2 1 3 2 2 Input Image, f Convolution 1 1 1 2 2 2 3 -1 2 1 2 1 3 3 -1 -1 1 2 2 1 2 1 3 2 2 1 1 1 2 2 -2 6 1 5 4 4 -2 Output 2 1 -3 -3 1 Image, g 2 2 1 2 1 3 2 2 Input Image, f Solution 5 4 4 -2 9 6 14 5 11 7 6 5 9 12 8 5 Final output Image, g Example of Correlation correlation kernel, ω 1 -1 -1 Input Image f 1 2 -1 2 2 2 3 1 1 1 2 1 3 3 Don’t rotate use it directly 2 2 1 2 1 3 2 2 Correlation 1 -1 -1 2 2 2 3 1 2 -1 2 1 3 3 1 1 1 2 2 1 2 1 3 2 2 1 -1 -1 1 4 -2 2 3 5 1 2 1 3 3 output Image, g 2 2 1 2 1 3 2 2 Input Image, f Correlation 1 -1 -1 2 2 2 3 1 2 -1 2 1 3 3 1 1 1 2 2 1 2 1 3 2 2 1 -1 -1 2 4 -2 3 5 10 2 1 3 3 output Image, g 2 2 1 2 1 3 2 2 Input Image, f Correlation 1 -1 -1 2 2 2 3 1 2 -1 2 1 3 3 1 1 1 2 2 1 2 1 3 2 2 1 -1 -1 2 2 4 -3 5 10 10 2 1 3 3 output Image, g 2 2 1 2 1 3 2 2 Input Image, f Correlation 1 -1 -1 2 2 2 3 1 2 -1 2 1 3 3 1 1 1 2 2 1 2 1 3 2 2 1 -1 -1 2 2 2 6 -1 5 10 10 15 2 1 3 3 1 output Image, g 2 2 1 2 1 3 2 2 Input Image, f Correlation 5 10 10 15 3 4 6 11 7 11 4 9 -5 4 4 5 Final output Image, g Spatial Filters Spatial filters can be classified by effect into:  Smoothing Spatial Filters: also called low pass filters. They include: 1. Averaging linear filters 2. Order-statistics nonlinear filters.  Sharpening Spatial Filters: also called high pass filters. For example, the Laplacian linear filter. Smoothing Spatial Filters  Smoothing spatial filter are used for blurring and for noise reduction. Blurring is used in pre-processing steps to:  Remove small details from an image prior to (large) object extraction  Bridge small gaps in lines or curves.  Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear filtering. Smoothing linear filters: Low Pass Filtering  Averaging Filter removes the noise by blurring till it is no longer seen.  It blurs the edges too.  Bigger the averaging mass more the blurring.  Sometimes the image contains ‘salt & pepper noise’.  If averaging filter is used then it will remove the noise at the cost of ruined edges.  Thus a nonlinear filter Median filter is required.  They are also called as order statistics filter since their response is based on ordering or ranking of pixels contained within the mask.  Here we use a blank mask. Smoothing linear filters: Average Linear Filter  The response of averaging filter is simply the average of the pixels contained in the neighbourhood of the filter mask.  The output of averaging filters is a smoothed image with reduced "sharp" transitions in gray levels.  Noise and edges consist of sharp transitions in gray levels. Thus smoothing filters are used for noise reduction; however, they have the undesirable side effect that they blur edges.  The figure in next slide shows two 3×3 averaging filters. 1 1 1 1 2 1 1 1 ∗ 1 1 1 ∗ 2 4 2 9 16 1 1 1 1 2 1 Standard average filter Weighted average filter Note: Weighted average filter has different coefficients to give more importance (weight) to some pixels at the expense of others. The idea behind that is to reduce blurring in the smoothing process. Averaging linear filtering of an image f of size M× N with a filter mask of size m× n is given by the expression: To generate a complete filtered image this equation must be applied for x = 0,1, 2,..., M-1 and y = 0,1, 2,..., N-1. Figure: Effect of averaging filter a) Original Image, b)-f) Results of Smoothing with square averaging filter masks of sizes n=3,5,9,15 and 35 respectively. Effect of Average Linear Filter As shown in the figure, the effects of averaging linear filter are:  Blurring which is increased whenever the mask size increases.  Blending (removing) small objects with the background. The size of the mask establishes the relative size of the blended objects.  Black border because of padding the borders of the original image.  Reduced image quality. Smoothing Non- linear filters: Order-statistics filters  OSF are nonlinear spatial filters whose response is based on ordering (ranking) the pixels contained in the neighbourhood, and then replacing the value of the center pixel with the value determined by the ranking result.  Examples include Max, Min, and Median filters. Max Filter:  It is used to find the brightest points in an image.  Response of a 3 x 3 max filter is given by Min Filter:  Used to find the darkest points in an image. Median filter  It replaces the value at the center by the median pixel value in the neighbourhood, (i.e. the middle element after they are sorted).  Median filters are particularly useful in removing impulse noise (also known as salt-and-pepper noise). Salt = 255, pepper = 0 gray levels.  In a 3×3 neighbourhood the median is the 5th largest value, in a 5×5 neighbourhood the 13th largest value, and so on.  For example, suppose that a 3×3 neighbourhood has gray levels (10, 20, 0, 20, 255, 20, 20, 25, 15). These values are sorted as (0,10,15,20,20,20,20,25,255), which results in a median of 20 that replaces the original pixel value 255 (salt noise). Steps to perform median filtering  Assume a 3x3 empty mask.  Place the empty mask at the Left Hand corner.  Arrange the 9 pixels in ascending or descending order.  Choose the median from these 9 values.  Place the median at the centre.  Move the mask in same manner as averaging filter. Problem 1: Consider the following 5×5 image: 20 30 50 80 100 Apply a 3×3 median filter on the 30 20 80 100 110 shaded pixels, and write the filtered image. 25 255 70 0 120 30 30 80 100 130 40 50 90 125 140 Solution 20 30 50 80 100 20 30 50 80 100 30 20 80 100 110 30 20 80 100 110 25 255 70 0 120 25 255 70 0 120 30 30 80 100 130 30 30 80 100 130 40 50 90 125 140 40 50 90 125 140 Sort: 20, 25, 30, 30, 30, 70, 80, 80, 255 Sort 0, 20, 30, 70, 80, 80, 100, 100, 255 20 30 50 80 100 30 20 80 100 110 25 255 70 0 120 30 30 80 100 130 40 50 90 125 140 Sort 0, 70, 80, 80, 100, 100, 110, 120, 130 20 30 50 80 100 30 20 80 100 110 25 30 80 100 120 Filtered Image = 30 30 80 100 130 40 50 90 125 140 Problem 2: Apply 3x3 median filter to find a new image. 3 4 2 3 1 7 3 2 4 5 3 8 2 3 1 7 3x3 blank mask Filter Applied on next neighbourhood pixel 7 Filtered Image 3 4 2 3 3 4 2 3 1 7 3 2 1 3 2 4 5 3 8 2 3 1 7 4 8 2 3 1 7 Sorted List after median filter 1) 1 2 3 3 3 4 4 5 7 Filter Applied on next neighbourhood pixel 3 Filtered Image 3 4 2 3 3 4 2 3 1 7 3 2 1 3 3 2 4 5 3 8 4 8 2 3 1 7 2 3 1 7 Sorted List after median filter 1) 1 2 3 3 3 4 4 5 7 2) 2 2 3 3 3 4 5 7 8 Filter Applied on next neighbourhood pixel 5 Filtered Image 3 4 2 3 3 4 2 3 1 7 3 2 1 3 3 2 4 5 3 8 4 3 8 2 3 1 7 2 3 1 7 Sorted List after median filter 1) 1 2 3 3 3 4 4 5 7 2) 2 2 3 3 3 4 5 7 8 3) 1 1 2 3 3 3 4 5 7 Filter Applied on next neighbourhood pixel 3 Final Filtered Image 3 4 2 3 3 4 2 3 1 7 3 2 1 3 3 2 4 5 3 8 4 3 3 8 2 3 1 7 2 3 1 7 Sorted List after median filter 1) 1 2 3 3 3 4 4 5 7 2) 2 2 3 3 3 4 5 7 8 3) 1 1 2 3 3 3 4 5 7 4) 1 2 3 3 3 5 7 7 8 Problem 3: Apply 3x3 median filter to find a new image 2 4 15 0 3 5 2 6 11 0 2 10 6 16 0 2 Problem 4: If x = {2 3 4 3 4 5 6} & w = {-1 0 1}, perform median filtering. size of mask is 1x3. Term ‘0’ indicates the position from where filtering starts. Result: {2 3 3 4 4 5 6} Figure Effect of median filter. (a) Image corrupted by salt & pepper noise. (b) Result of applying 3×3 standard averaging (b) filter on (a). (c) (a) Result of applying 3×3 median filter on (a). As shown in the figure, the effects of median filter (application of smoothing filters)are: 1. Noise reduction 2. Less blurring than averaging linear filter (c) Sharpening Spatial Filters  Sharpening aims to highlight fine details (e.g. edges) in an image, or enhance detail that has been blurred through errors or imperfect capturing devices.  Image blurring can be achieved using averaging filters, and hence sharpening can be achieved by operators that invert averaging operators.  In mathematics, averaging is equivalent to the concept of integration, and differentiation inverts integration. Thus, sharpening spatial filters can be represented by partial derivatives. 1. High Pass Filter  Retains HF component while eliminates LF components.  High passed image will have no background(Low frequency region).  It will have enhanced edges.  Its used to sharpen blurred images.  Process of mask moving on image is same only the mask coefficients change.  Mask coefficients should have positive value at centre and negative values elsewhere.  Sum of coefficients must be zero.  Since, it should give Zero after being placed on LP region. High Pass Masks Some Example of 3x3 High pass masks -1 -1 -1 -1 8 -1 -1 -1 -1 0 -1 0 -1 -2 -1 -1 4 -1 -2 12 -2 0 -1 0 -1 -2 -1 2. Partial Derivatives Filter The first order partial derivatives of the digital image f(x,y) are, The first derivative must be: 1. zero along flat segments (i.e. constant gray intensity values). 2. non-zero at the outset of gray level step or ramp (edges or noise) 3. non-zero along segments of continuing changes (i.e. ramps). The second order partial derivatives of the digital image f(x,y) are: The second derivative must be: 1. zero along flat segments(i.e. constant gray intensity values). 2. nonzero at the outset and end of a gray-level step or ramp; 3. zero along ramps Observation from the figure  First order derivative produces thick edges, while the second order derivative produces much finer ones.  Second order derivative has a much stronger response to fine detail, such as thin lines, edge and isolated points including noise.  First order derivative generally have a stronger response at the step.  Second order derivative produces a double response at step changes in grey level. The Laplacian Filter  Isotropic Filter: They are rotation invariant.  Laplacian is simplest Isotropic derivative operator. It is defined as  Since the Laplacian filter is a linear spatial filter, we can apply it using the same mechanism of the convolution process.  This will produce a laplacian image that has grayish edge lines and other discontinuities, all superimposed on a dark, featureless background.  If background features need to be recovered by still preserving the sharpening effect of the Laplacian, then  The basic way to use the Laplacian for image sharpening is:  Background features can be "recovered" while still preserving the sharpening effect of the Laplacian operation simply by adding the original and Laplacian images. If the center coefficient of the Laplacian mask is negative If the center coefficient of the Laplacian mask is positive The 2D Laplacian (a) (b) Example of applying Laplacian filter. (a) Original image.(Courtesy by NASA) (b) Laplacian image (c) Sharpened image. (c) Application of Sharpening Filter  Highlight fine detail  Enhance detail that has been blurred  To express the equation in discrete form, In x-direction and y-direction Thus, discrete Laplacian of 2 variables is, The Gradient  The most common method of differentiation in image processing applications is the gradient.  f  Gx   x  f      f  G y     y    2  f   f  2 2 1/ 2 f  mag (f )  Gx  G y       2  x   y   Its magnitude can be approximated in a number of ways, which result in a number of operators such as Roberts, Prewitt and Sobel operators for computing its value. Example of masks of various operators Combining spatial enhancement methods (a)(b) (c)(d) (a)Image of whole body bone scan, (b) Laplacian of (a), (c)Sharpen image by adding (a), (d)Sobel of (a) (e)(f) (g)(h) (e)Sobel image smoothed with a 5*5 averaging filter, (f)Mask image form by the product of (c) & (e), (g)Sharpen image obtain by adding (a) & (f), (h)Final image obtain by power law transformation to (g) Unsharp Masking  A process used for many years in publishing industries for image sharpening  Consist of subtracting a blurred version of image from the image itself.  This process called “unsharp Masking”. Reference 1. Digital Image Processing 3rd Edition © 2002 R. C. Gonzalez & R. E. Woods 2. Dr. Devang Pandya, Assistant Professor, ICT department, AIIE 3. Assistant Professor Wasseem Nahy Ibrahem, University of Technology, Iraq 4. Video lectures on Digital Image Processing, Golamreza Anbarjafari, PhD 5. University of Regina/Image Processing :http://www.cs.uregina.ca/Links/class-info/425

Use Quizgecko on...
Browser
Browser