210 likes | 274 Vues
Image Processing. Chapter(3) Part 4:Intensity Transformation and spatial filters Prepared by: Hanan Hardan. Ch3, lesson 6: spatial filters. Origin. x. (x, y). Neighbourhood. y. Image f (x, y). Spatial filters. Remember that types of neighborhood:
E N D
Image Processing Chapter(3) Part 4:Intensity Transformation and spatial filters Prepared by: Hanan Hardan
Ch3, lesson 6: spatial filters Origin x (x, y) Neighbourhood y Image f (x, y) Spatial filters Remember that types of neighborhood: • intensity transformation: neighborhood of size 1x1 • 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 (x, y) Neighbourhood y Image f (x, y) Neighbourhood Operations • For each pixel in the origin image, the outcome is written on the same location at the target image. Origin Target
Simple Neighbourhood Operations • Simple neighbourhood operations example: • Min: Set the pixel value to the minimum in the neighbourhood • Max: Set the pixel value to the maximum in the neighbourhood
a b c d e f g h i j k l m n o p q r The Spatial Filtering Process Origin x * Original Image Pixels Filter (w) Simple 3*3Neighbourhood 3*3 Filter eprocessed = n*e + j*a + k*b + l*c + m*d + o*f + p*g + q*h + r*i e y Image f (x, y) The above is repeated for every pixel in the original image to generate the filtered image
Ch3, lesson 5: spatial filters Spatial filters • Smoothing Spatial filters [low pass]. • Sharpening Spatial Filters[high pass].
Ch3, lesson 6: Smoothing filters Spatial filters : Smoothing ( low pass) • Use:for blurring and noise reduction. • Type of smoothing filters: • Standard average • weighted average. • 3. Median filter linear Order statistics
Smoothing Spatial Filters • One of the simplest spatial filtering operations we can perform is a smoothing operation • Simply average all of the pixels in a neighbourhood around a central value • Especially useful in removing noise from images • Also useful for highlighting gross detail Simple averaging filter
104 100 108 99 106 98 95 90 85 1/9 1/9 1/9 1/9 1/9 1/9 104 100 108 1/9 1/9 1/9 99 98 95 90 85 Smoothing Spatial Filtering Origin x * Original Image Pixels Filter Simple 3*3Neighbourhood 3*3 SmoothingFilter 106 e = 1/9*106 + 1/9*104 + 1/9*100 + 1/9*108 + 1/9*99 + 1/9*98 + 1/9*95 + 1/9*90 + 1/9*85 = 98.3333 y Image f (x, y) The above is repeated for every pixel in the original image to generate the smoothed image
Ch3, lesson 6: Smoothing filters Spatial filters : Smoothinglinear smoothing : averaging kernels • Standard average
Ch3, lesson 6: Smoothing filters Spatial filters : SmoothingStandard and weighted Average- example 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
Ch3, lesson 6: Smoothing filters What happens when the Values of the Kernel Fall Outside the Image??!
Ch3, lesson 6: Smoothing filters First solution :Zero padding, -ve: black border
Ch3, lesson 6: Smoothing filters border padding
Ch3, 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
Ch3, lesson 6: Smoothing filters Spatial filters : Smoothinglinear smoothing : averaging kernels • weighted average. Used to reduce blurring more.
Ch3, lesson 6: Smoothing filters Spatial filters : SmoothingStandard and weighted Average- example 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 =
Ch3, lesson 6: Smoothing filters Spatial filters : Smoothingorder statistics: Median filter becomes 95 Steps: 1. Sort the pixels in ascending order: 90,90, 91, 94, 95, 98, 99, 110, 120 2. replace the original pixel value by the median : 95
Ch3, lesson 6: Smoothing filters Spatial filters : Smoothingorder statistics: Median filter use : blurring + reduce salt and pepper noise The original image with salt and pepper noise The smoothed image using averaging The smoothed image using median
Smoothing Filters: Median Filtering(non-linear) • Very effective for removing “salt and pepper” noise). median filtering averaging
Ch3, lesson 7: sharpening filters Smoothing Filters: Example1: 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) Example2: v=imread('cameraman.tif'); x=imnoise(v,'salt & pepper', 0.02); xx=medfilt2(x); imshow(x),figure, imshow(xx) Note: medfilt2 (x,[a b]) where a and b the size of filter.