🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Digital Image Processing 3.2 copy.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Sudan University of Science and Technology Digital Image Processing Lecture 3.2 Image Enhancement in the Spatial Domain Dr. Jacqueline. J. George Outline n Spatial Filters n Spatial Correlation n Spatial Convolution Dr. Jacqueline.J.Ge...

Sudan University of Science and Technology Digital Image Processing Lecture 3.2 Image Enhancement in the Spatial Domain Dr. Jacqueline. J. George Outline n Spatial Filters n Spatial Correlation n Spatial Convolution Dr. Jacqueline.J.George 2 Spatial Filtering n Also called the neighborhood processing. n Refers to processing a pixel using neighbors surrounding it. n This area is called a filter, mask, kernel, template, or window. n The values for the filter are known as coefficients rather than pixels. n At each point (x,y), the response of the filter is calculated by a sum of products of the filter coefficients and the corresponding image pixels in the area spanned by the filter mask. Dr. Jacqueline.J.George 3 Linear Spatial Filtering n In general for, linear filtering of an image f of size MxN with a filter mask of size mxn is given by the following expression a b g ( x, y) = å å w( s, t ) f ( x + s, y + t ) s =- a t =- b where a = (m –1)/2 b= (n –1)/2 Dr. Jacqueline.J.George 4 Spatial Filtering n The response of the mask will then be Dr. Jacqueline.J.George 5 Spatial Filtering n R will be positioned in exactly position z5 in the output image. Dr. Jacqueline.J.George 6 Spatial Filtering n The mask will then be centered at z6 and a new R will be computed in the same manner and positioned at the same location in the output image. n The whole process is repeated from left to right and top to bottom n Normally the mask is of odd size e.g. 3x3, 5x5 etc. so that the center of the mask in symmetrical. Dr. Jacqueline.J.George 7 Linear vs Non-Linear Spatial Filtering Methods n A filtering method is linear when the output is a weighted sum of the input pixels. n Methods that do not satisfy this property are called non-linear. n e.g., Dr. Jacqueline.J.George 8 Example Find the output of the spatial filter of A by M. é0 0 0 0 0ù0 0 ê0 0 0 0 0úú 0 0 ê ê0 0 1 1 0ú0 0 ê ú é1 / 9 1 / 9 1 / 9ù A = ê0 0 1 1 0ú0 0 M = êê1 / 9 1 / 9 1 / 9úú ê0 0 0 0 0 0 0ú ê ú êë1 / 9 1 / 9 1 / 9úû ê0 0 0 0 0 0 0ú ê0 0 0 0 0 0 0úû ë Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9.......... 0 0 1 1 0 0 0.............. 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9........ 0 0 1 1 0 0 0.............. 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9...... 0 0 1 1 0 0 0.............. 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9.... 0 0 1 1 0 0 0.............. 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9 0.. 0 0 1 1 0 0 0.............. 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9 0.. 0 0 1 1 0 0 0.. 2/9.......... 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9 0.. 0 0 1 1 0 0 0.. 2/9 4/9........ 0 0 1 1 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Solution Original image Processed image 0 0 0 0 0 0 0.............. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9 0.. 0 0 1 1 0 0 0.. 2/9 4/9 4/9 2/9 0.. 0 0 1 1 0 0 0.. 2/9 4/9 4/9 2/9 0.. 0 0 0 0 0 0 0.. 1/9 2/9 2/9 1/9 0.. 0 0 0 0 0 0 0.. 0 0 0 0 0.. 0 0 0 0 0 0 0.............. é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Linear Spatial Filtering Methods n At the border of the image, as many as a rows and columns would not be able to compute since the mask will go out of the boundary of the image. n Solutions to these problem n Simply ignore the rows and columns. Thus the output image will be smaller in size than the original. n Use different methods such as; Zero Boundary, Replicate the boundary pixels and Periodic images Dr. Jacqueline.J.George 18 Zero Boundary n The values of the pixels outside the boundary of the image are set to zero. 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.4 0.0 0.6 0.3 0.2 0.0 0.0 0.8 0.3 0.7 0.2 0.7 0.0 0.0 0.5 0.4 0.7 0.5 0.3 0.0 0.0 0.5 0.3 0.6 0.8 0.7 0.0 0.0 0.9 0.3 0.0 0.7 0.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 Zero Boundary n Assuming a black border outside the image can create artifacts in spatial linear filtering. Zero Boundary Original image 10 iterations Filtered image of filtering é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Replicate the Boundary Pixels n Replicate the pixels at the boundary of the image. 0.4 0.4 0.0 0.6 0.3 0.2 0.2 0.4 0.4 0.0 0.6 0.3 0.2 0.2 0.8 0.8 0.3 0.7 0.2 0.7 0.7 0.5 0.5 0.4 0.7 0.5 0.3 0.3 0.5 0.5 0.3 0.6 0.8 0.7 0.7 0.9 0.9 0.3 0.0 0.7 0.2 0.2 0.9 0.9 0.3 0.0 0.7 0.2 0.2 Replicate the Boundary Pixels n By replicating boundary pixels we can avoid artifacts in spatial linear filtering. Original image 10 iterations of filtering é1 / 9 1 / 9 1 / 9ù M = êê1 / 9 1 / 9 1 / 9úú êë1 / 9 1 / 9 1 / 9úû Periodic Images n Replicate the whole image as a 2D periodic tile. Periodic images n Replicate the whole image as a 2D periodic tile. 0.2 0.9 0.3 0.0 0.7 0.2 0.9 0.2 0.4 0.0 0.6 0.3 0.2 0.4 0.7 0.8 0.3 0.7 0.2 0.7 0.8 0.3 0.5 0.4 0.7 0.5 0.3 0.5 0.7 0.5 0.3 0.6 0.8 0.7 0.5 0.2 0.9 0.3 0.0 0.7 0.2 0.9 0.2 0.4 0.0 0.6 0.3 0.2 0.4 Region of Interest (ROI) n A region of interest (ROI) is a part of the image which we want to process separately. n Spatial filters are often applied on regions of interests. x2 zoom x2 zooming algorithm: 1. Given an nxn image A, create a new (2n)x(2n) image A’ such that: The values of the pixels of A are copied on the pixels A’ with both coordinates even. The values of the other pixels of A' are set to zero. 2. Smooth A' with a spatial linear filter. x2 zoom The values of the pixels of A are copied on the pixels A' with both coordinates even. The other pixels of A' have zero values. 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.1 0.0 0.6 0.5 0.1 0.6 0.0 0.0 0.0 0.0 0.0 0.0 0.8 0.3 0.7 0.0 0.8 0.0 0.3 0.0 0.7 0.5 0.4 0.7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.4 0.0 0.7 x2 zoom The values of the pixels of A are copied on the pixels of A' with both coordinates even. The other pixels of A' have zero values. x2 zoom The second step is to smooth A' with a spatial linear filter. 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5........ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5 0.3...... 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5 0.3 0.1.... 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5 0.3 0.1 0.35.. 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5 0.3 0.1 0.35.. 0.0 0.0 0.0 0.0 0.0 0.0.. 0.65........ 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.1 0.0 0.6.. 0.5 0.3 0.1 0.35.. 0.0 0.0 0.0 0.0 0.0 0.0.. 0.65 0.4...... 0.0 0.8 0.0 0.2 0.0 0.7............ 0.0 0.0 0.0 0.0 0.0 0.0............ 0.0 0.5 0.0 0.4 0.0 0.7............ é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû x2 zoom x2 zoom The zooming algorithm with the mask é1 / 4 1 / 2 1 / 4ù M = êê1 / 2 1 1 / 2úú êë1 / 4 1 / 2 1 / 4úû is called 1-order interpolation zooming. Each pixel of A' is the average of the pixels of A around it. 1-order interpolation zooming is simple and fast, but the results are generally poor. x2 zoom 1-order interpolation zooming can be implemented directly. From an n xn image A, create a (2n)x(2n) image A' using the rules A' (2i,2 j ) = A(i, j ) A' (2i,2 j + 1) = ( A(i, j ) + A(i, j + 1)) / 2 A' (2i + 1,2 j ) = ( A(i, j ) + A(i + 1, j )) / 2 A' (2i + 1,2 j + 1) = ( A(i, j ) + A(i, j + 1) + A(i + 1, j ) + A(i + 1, j + 1)) / 4 x4 zoom We can repeat the process to obtain x4, x8, x16, … , zooms of the original. x4 x2 x1 Spatial Correlation The correlation of a filter w( x, y ) of size m ´ n with an image f ( x, y ), denoted as w( x, y ) f ( x, y ) a b w( x, y ) f ( x, y ) = å å w(s, t ) f ( x + s, y + t ) s =- a t =- b 40 Spatial Convolution The convolution of a filter w( x, y ) of size m ´ n with an image f ( x, y ), denoted as w( x, y ) f ( x, y ) a b w( x, y ) f ( x, y ) = å å w(s, t ) f ( x - s, y - t ) s =- a t =- b 41 8/8/24 42

Use Quizgecko on...
Browser
Browser