Image Processing Chapter3 Part 4 Intensity Transformation and





![Ch 3, lesson 5: spatial filters Spatial filters 1. Smoothing Spatial filters [low pass]. Ch 3, lesson 5: spatial filters Spatial filters 1. Smoothing Spatial filters [low pass].](https://slidetodoc.com/presentation_image/e7319af11593267b3a534eeaef48194f/image-6.jpg)















- Slides: 21

Image Processing Chapter(3) Part 4: Intensity Transformation and spatial filters Prepared by: Hanan Hardan

Ch 3, lesson 6: spatial filters Spatial filters Remember that types of neighborhood: p p p intensity transformation: neighborhood of size 1 x 1 spatial filter (or mask , kernel, template or window): neighborhood of larger size , like 3*3 mask The spatial filter mask is moved from point to point in an image. At each point (x, y), the response of the filter is calculated Origin x Neighbourhood y (x, y) Image f (x, y)

Neighbourhood Operations p For each pixel in the origin image, the outcome is written on the same location at the target image. Origin Neighbourhood y x (x, y) Image f (x, y) Targe t

Simple Neighbourhood Operations p. Simple neighbourhood operations example: n Min: Set the pixel value to the minimum in the neighbourhood n Max: Set the pixel value to the maximum in the neighbourhood

The Spatial Filtering Process Origin x Simple 3*3 Neighbourhood y e 3*3 Filter a b c d e f g h i Original Image Pixels * j k l m n o p q r Filter (w) eprocessed = n*e + j*a + k*b + l*c + m*d + o*f + p*g + q*h + r*i Image f (x, y) The above is repeated for every pixel in the original image to generate the filtered image
![Ch 3 lesson 5 spatial filters Spatial filters 1 Smoothing Spatial filters low pass Ch 3, lesson 5: spatial filters Spatial filters 1. Smoothing Spatial filters [low pass].](https://slidetodoc.com/presentation_image/e7319af11593267b3a534eeaef48194f/image-6.jpg)
Ch 3, lesson 5: spatial filters Spatial filters 1. Smoothing Spatial filters [low pass]. 2. Sharpening Spatial Filters[high pass].

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing ( low (pass Use: for blurring and noise reduction. Type of smoothing filters: 1. Standard average 2. weighted average. 3. Median filter linear Order statistics

Smoothing Spatial Filters p. One of the simplest spatial filtering operations we can perform is a smoothing operation n Simply average all of the pixels in a neighbourhood around a central value Especially useful 1/ 1/ 1/ in removing noise 9 9 9 from images Simple averaging Also useful for 1/ 1/ 1/ 9 9 9 filter highlighting gross detail 1 1 1 /9 /9 /9

Smoothing Spatial Filtering Origin x 104 100 108 99 106 98 95 Simple 3*3 Neighbourhood y 1/ 100108 1 1 104 9 /9 /9 1/ 1106 1/ 99 9 /9 98 9 195 /9 190 /9 185 /9 90 85 Original 3*3 Smoothing Image Filter Pixels Image f (x, y) * Filter e = 1/9*106 + 1/9*104 + 1/9*100 + 1/ *108 + 1/ *99 + 1/ *98 + 1/ *95 + 9 9 1/ *90 + 1/ *85 = 98. 3333 9 9 The above is repeated for every pixel in the original image to generate the smoothed image

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing linear smoothing : averaging kernels Standard average

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing Standard and weighted Average- example 110 120 90 130 91 94 98 200 90 91 99 100 82 96 85 90 The mask is moved from point to point in an image. At each point (x, y), the response of the filter is calculated Standard averaging filter: (110 +120+90+91+94+98+90+91+99)/9 =883/9 = 98. 1

Ch 3, lesson 6: Smoothing filters What happens when the Values of the Kernel Fall Outside the Image? ? !

Ch 3, lesson 6: Smoothing filters First solution : Zero padding, -ve: black border

Ch 3, lesson 6: Smoothing filters border padding

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing Averaging effects: blurring + reducing noise Original image 3 x 3 averaging 5 x 5 averaging 9 x 9 averaging 15 x 15 averaging 35 x 35 averaging Notice how detail begins to disappear

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing linear smoothing : averaging kernels weighted average. Used to reduce blurring more.

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing Standard and weighted Average- example 110 120 90 130 91 94 98 200 90 91 99 100 82 96 85 90 The mask is moved from point to point in an image. At each point (x, y), the response of the filter is calculated : Weighted averaging filter: (110 +2 x 120+90+2 x 91+4 x 94+2 x 98+90+2 x 91+99)/16 =

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing order statistics: Median filter 110 120 90 130 91 94 98 200 90 95 99 100 82 96 85 90 becomes 95 Steps: 1. Sort the pixels in ascending order: 90, 91, 94, 95, 98, 99, 110, 120 2. replace the original pixel value by the median : 95

Ch 3, lesson 6: Smoothing filters Spatial filters : Smoothing order statistics: Median filter use : blurring + reduce salt and pepper noise The original image The smoothed with salt and image using pepper noise averaging The smoothed image using median

Smoothing Filters: Median Filtering (non-linear) p Very effective for removing “salt and pepper” noise). averaging median filtering

Ch 3, lesson 7: sharpening filters Smoothing Filters: Example 1: v=imread('cameraman. tif'); x=imnoise(v, 'salt & pepper', 0. 02); % added noise to the image h=fspecial('average', [3 3]); % create a two-dimensional filter xx=imfilter(x, h); % apply the filter on the image imshow(x), figure, imshow(xx) Example 2: v=imread('cameraman. tif'); x=imnoise(v, 'salt & pepper', 0. 02); xx=medfilt 2(x); imshow(x), figure, imshow(xx) Note: medfilt 2 (x, [a b]) where a and b the size of filter.