You are on page 1of 21

ECE 468 / CS 519:

Digital Image Processing

Spatial Filtering

Prof. Sinisa Todorovic

sinisa@eecs.oregonstate.edu

1
Outline

MATLAB

Smoothing spatial filters (Textbook: 3.5)

2
MATLAB

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

If high_out < low_out, the output is a photographic negative.

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

If high_out < low_out, the output is a photographic negative.

h = imhist(f, num_bins);% histogram

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

If high_out < low_out, the output is a photographic negative.

h = imhist(f, num_bins);% histogram

p = imhist(f, num_bins)/numel(f);% normalized histogram

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

If high_out < low_out, the output is a photographic negative.

h = imhist(f, num_bins);% histogram

p = imhist(f, num_bins)/numel(f);% normalized histogram

g = histeq(f, hspec), or g = histeq(f,256)

3
MATLAB

g = imadjust(f,[low_in; high_in],[low_out; high_out],gamma)

If high_out < low_out, the output is a photographic negative.

h = imhist(f, num_bins);% histogram

p = imhist(f, num_bins)/numel(f);% normalized histogram

g = histeq(f, hspec), or g = histeq(f,256)

hspec - counts of equally spaced intensity values in [0,255]

3
Linear Spatial Filtering

a b
g(x, y) = w(i, j)f (x + i, y + j)
i= a j= b

4
Linear Spatial Filtering

5
Correlation vs. Convolution

Correlation:
1. Move the filter mask to a location

2. Compute the sum of products

3. Go to 1. a b
w(x, y) f (x, y) = w(i, j)f (x + i, y + j)
i= a j= b

Convolution:
1. Rotate the filter mask by 180 degrees

2. Correlation
a b
w(x, y) f (x, y) = w(i, j)f (x i, y j)
i= a j= b
6
Example: Correlation vs. Convolution

7
Example: Correlation vs. Convolution

8
Example: Correlation vs. Convolution

9
Example: Correlation vs. Convolution

10
Gaussian Filter
x +y 2 2
N (x, y) = exp( )
2 2
3x3 filter:

w1 = N ( 1, 1), w2 = N ( 1, 0), . . . w9 = N (1, 1)

11
Smoothing Filter -- Low Pass Filter

spatial averaging weighted averaging

12
Example: Smoothing Filter

13
Application of Smoothing

an image from Hubble space telescope

input output thresholded

14
Application of Smoothing

15

You might also like