Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spatial Filtering Dr. Amnach Khawne.

Similar presentations


Presentation on theme: "Spatial Filtering Dr. Amnach Khawne."— Presentation transcript:

1 Spatial Filtering Dr. Amnach Khawne

2 OUTLINE Type of noise Noise Model Neighborhood Processing
Spatial domain operation or filtering – Linear filtering – Non-linear filtering – Adaptive filtering

3 Noise We may define noise to be any degradation in the image signal.
Cleaning an image corrupted by noise is thus an important area of image restoration. We can consider a noisy image to be modelled as follows: where f(x, y) is the original image pixel, (x, y) is the noise term and g(x, y) is the resulting noisy pixel

4 Understanding Sources of Noise in Digital Images
 Noise is the result of errors in the image acquisition process that result in pixel values that do not reflect the true intensities of the real scene. There are several ways that noise can be introduced into an image, depending on how the image is created. Source:

5 Understanding Sources of Noise in Digital Images (con’t)
For example of introduced noise: If the image is scanned from a photograph made on film, the film grain is a source of noise. Noise can also be the result of damage to the film, or be introduced by the scanner itself. If the image is acquired directly in a digital format, the mechanism for gathering the data (such as a CCD detector) can introduce noise. Electronic transmission of image data can introduce noise.

6 Measure of the sensitivity of a (digital or film) imaging system
The signal-to-noise ratio (SNR) is used in imaging as a physical measure of the sensitivity of a (digital or film) imaging system. Industry standards measure SNR in decibels (dB)  SNR = 10log10[var(image)/var(noise)] Source:

7 Noise Models There are many different models for the image noise term η(x, y): Gaussian Most common model Rayleigh Erlang Exponential Uniform Impulse Salt and pepper noise Images taken from Gonzalez & Woods, Digital Image Processing (2002) Gaussian Rayleigh Erlang Exponential Uniform Impulse Souce: Lawrence Rabiner

8 Impulse (Salt and pepper noise)

9 Impulse (Salt and pepper noise)

10 Types of noise Salt and pepper noise Gaussian noise Speckle noise
Periodic noise Speckle noise Periodic noise

11 Noise Distributions in the Real World
• Gaussian noise occurs in imaging sensors operating at low light levels • Salt-and-pepper noise arises in faulty switching devices • Rayleigh noise arises in range imaging • Exponential and Erlang noise occur in laser imaging Souce: Lawrence Rabiner

12 Gaussian noise Gaussian noise occurs in imaging sensors operating at low light levels z represents gray level,  is the mean of average value of z;  is its standard deviation

13 Gaussian noise Gaussian noise is an idealized form of white noise, which is caused by random fluctuations in the signal. We can observe white noise by watching a television which is slightly mistuned to a particular channel. Gaussian noise is white noise which is normally distributed. I = imread('eight.tif'); I1=imnoise(I,‘gaussian'); imshow(I1)

14 Reasons for Salt and Pepper Noise
By memory cell failure. By malfunctioning of camera’s sensor cells. By synchronization errors in image digitizing or transmission. The PDF of (bipolar) impulse noise is given by

15 Impulse noise (Salt and pepper noise)
The salt and pepper noise is generally caused by mulfunction of the camera’s sensor cells, by memory cell failure or by synchronization errors in the image digitizing or transmission and also called impulse noise, shot noise, or binary noise. This degradation can be caused by sharp, sudden disturbances in the image signal. Its appearance is randomly scattered white or black (or both) pixels over the image. I = imread('eight.tif'); I1=imnoise(I,'salt & pepper'); imshow(I1) The amount of noise added defaults to 10% The value is set between 0 and 1 indicating the fraction of pixels to be corrupted

16 Speckle noise I = imread('eight.tif'); I1=imnoise(I,'speckle');
Gaussian noise can be modeled by random values added to an image; speckle noise (or more simply just speckle) can be modeled by random values multiplied by pixel values, hence it is also called multiplicative noise. Speckle noise is a major problem in some radar applications I = imread('eight.tif'); I1=imnoise(I,'speckle'); imshow(I1)

17 Periodic noise If the image signal is subject to a periodic, rather than a random disturbance, we might obtain an image corrupted by periodic noise. The function imnoise does not have a periodic option >>I = imread('eight.tif'); >> s=size(I); >> [x,y]=meshgrid(1:s(1),1:s(2)); >> p=sin(x/3+y/5)+1; >>p1=p’; >> I1=(im2double(I)+p1/2)/2; >> imshow(I1)

18 MATLAB Noise Generation
• A = rand(M, N) – generates M x N array of uniformly distributed numbers in interval (0, 1) • A = randn(M, N) – generates M x N array of Gaussian distributed numbers with zero mean and unit variance • g = imnoise(f, type, parameters) – adds M x N array of noise of various types (e.g., ‘gaussian’, ‘salt & pepper’, ‘speckle’, ‘poisson’) to an existing image, f • R = imnoise2(type, M, N, a, b) – generates M x N array of noise of types (‘uniform’,’gaussian’,’salt &pepper’,’lognormal’,’rayleigh’,’exponential’,’erlang’) – no scaling of noise array to (0, 1) interval – ‘salt & pepper’ noise has three values – 0 for pepper noise, 1 for salt noise, and 0,5 for no noise

19 Kernel Generation h = fspecial(type) h = fspecial(type, parameters)
'average' averaging filter 'gaussian' Gaussian lowpass filter H = fspecial('average',HSIZE) returns an averaging filter H of size. The default HSIZE is [3 3]. h = fspecial('gaussian', hsize, sigma) returns a rotationally symmetric Gaussian lowpass filter. The default value for hsize is [3 3]; the default value for sigma is 0.5.

20 Neighborhood Processing

21 Neighborhood Processing
Neighborhood processing may be considered as an extension of point processing, where a function is applied to a neighborhood of each pixel. The idea is to move a mask: a rectangle (usually with sides of odd length) or other shape over the given image.

22 a filter The combination of mask and function is called a filter

23 neighborhood operation
Local neighborhood and kernel (mask) The most common neighborhood operation is to multiply each of the pixels in the neighborhood by a weight and add them together The local weights are sometimes called a mask or kernel

24

25 spatial filtering is spatial convolution
MASK

26 2D convolution ที่มา :

27 Notation

28 Excercise A = rand(3); B = rand(4); C = conv2(A,B,'same')
A convolution B

29 Annoying details What is the size of the output?
MATLAB: conv2(f, g,shape) shape = ‘full’: output size is sum of sizes of f and g shape = ‘same’: output size is same as f shape = ‘valid’: output size is difference of sizes of f and g full same valid g g g g f f g f g g g g g g g Source: S. Marschner

30 Notation

31 Applied filter on image
Source;

32

33 Edges of the image Ignore the edges. Pad with zeros.
This means all pixels except for the edges, and results in an output image which is smaller than the original. If the mask is very large, a significant amount of information may be lost by this method. return an output image of the same size as the original, but may have the effect of introducing unwanted artifacts (for example, edges) around the image.

34 Image Noise Reduction Linear Non-linear Neighborhood operators
Convolution Smoothing Filters called “Low-Pass” Filters blurring effect “pre-processing” removal of small details before object extraction noise reduction removal of noise in an image Non-linear Low-pass filter

35 Image Noise Reduction by Filter
Filter refers to accepting (passing) or rejecting certain frequency components. Filter

36     How do we clean up noise ? speckle noise Gaussian noise
Salt and pepper noise Gaussian noise Salt and pepper noise, Gaussian noise and speckle noise can all be cleaned by using spatial filtering techniques. “Periodic noise, however, requires image transforms for best results” Periodic noise

37 Filtering in MATLAB The filter2 function does the job of linear filterating for us; its use is filter2(filter,image,shape) 1 3 2

38 Linear filter

39 Cleaning Gaussian noise
Average filtering To cleaning Gaussian noise is to simply take the average the mean of all the images. suppose we have 100 copies of our image, I, each with noise, iN(0,)

40 Average filtering Averaging tends to blur an image
Average filter or Smoothing Filters or “Low-Pass” Filters Kernel original Using a 3x3 filter

41 Excercise >> I = imread('tire.tif');
>> ker = fspecial('average',3); >> Out = filter2(ker,I); >> figure;imshow(Out/255) >> ker = fspecial('average',9); >> ker = fspecial('average',15); original Using a 3x3 filter Using a 9x9 filter Using a 15x15 filter

42 Average filter Average filter 5x5

43 Use M(x,y) to compute values for mask. Gaussian Filter

44 Gaussian mask template generation
function template=gaussian_template(winsize,sigma) centre=floor(winsize/2)+1; %we'll normalise by the total sum sum=0; template=[]; %so work out the coefficients and the running total for i=1:winsize for j=1:winsize template(j,i)=exp(-(((j-centre)*(j-centre))+((i-centre)* (i-centre)))/(2*sigma*sigma)); sum=sum+template(j,i); end %and then normalise template=template/sum; Source:Feature Extraction &Image Processing for Computer Vision , Authers: Mark S. Nixon and Alberto S. Aguado

45 Gaussian filter Gaussian filter 5x5 Kernel 5x5

46 Order Statistics Filters
(Non-linear filter)

47 Cleaning salt and pepper noise
Median filtering seems almost tailor-made for removal of impulse or salt and pepper noise

48 Cleaning salt and pepper noise
Median filter Noisy image

49 Adaptive median filter
● Adaptive median filter changes size of Sxy (the size of the neighborhood) during operation. ● Notation Zmin = minimum gray level value in Sxy Zmax = maximum gray level value in Sxy Zmed = median of gray levels in Sxy Zxy = gray level at coordinates (x, y) Smax = maximum allowed size of Sxy Source : PENG Lei 

50 Adaptive median filter (algorithm)
Level A: A1 = Zmed - Zmin           A2 = Zmed - Zmax           if A1 > 0 AND A2 < 0, go to level B else increase the window size if window size < Smax, repeat level A else output Zxy Level B: B1 = Zxy - Zmin B2 = Zxy - Zmax if B1 > 0 AND B2 < 0, output Zxy else output Zmed Source : PENG Lei 

51 Level A: IF Zmin < Zmed < Zmax, then • Zmed is not an impulse
Explanation        Level A: IF Zmin < Zmed < Zmax, then                • Zmed is not an impulse                (1) go to level B to test if Zxy is an impulse ...                ELSE                • Zmed is an impulse                (1) the size of the window is increased and                (2) level A is repeated until ...                   (a) Zmed is not an impulse and go to level B or                   (b) Smax reached: output is Zxy Level B: IF Zmin < Zxy < Zmax, then                • Zxy is not an impulse                (1) output is Zxy (distortion reduced)                • either Zxy = Zmin or Zxy = Zmax                (2) output is Zmed (standard median filter)                • Zmed is not an impulse (from level A) Source : PENG Lei 

52 Adaptive Median Filter
I = imread('eight.tif'); g = imnoise(I, 'salt%pepper',0.25); J = imnoise(I,'salt & pepper', 0.25); K = medfilt2(J,[7 7],'symmetric'); imshow(J) figure; imshow(K) L = adpmedian(J, 7); figure; imshow(L) Median filter I+noise Adaptive median filter


Download ppt "Spatial Filtering Dr. Amnach Khawne."

Similar presentations


Ads by Google