Sie sind auf Seite 1von 102

DIP using Matlab

27 January 2013 2
1999-2007 by Richard Alan
Peters II
Prof. Peters in his home office. Needs a better shirt.
Image Compositing Example
27 January 2013 3
1999-2007 by Richard Alan
Peters II
This shirt demands a monogram.
Image Compositing Example
27 January 2013 4
1999-2007 by Richard Alan
Peters II
He needs some more color.
Image Compositing Example
27 January 2013 5
1999-2007 by Richard Alan
Peters II
Nice. Now for the way hed wear his hair if he had any.
Image Compositing Example
27 January 2013 6
1999-2007 by Richard Alan
Peters II
He cant stay in the office like this.
Image Compositing Example
27 January 2013 7
1999-2007 by Richard Alan
Peters II
Wheres a hepcat Daddy-O like this belong?
Image Compositing Example
27 January 2013 8
1999-2007 by Richard Alan
Peters II
In the studio!
Collar this jive,
Jackson. Like
crazy, Man !
Image Compositing Example
Image Formation
Image Formation
Image Formation
projection
through lens
image of object
Image Formation
projection onto
discrete sensor
array.
digital camera
Image Formation
sensors register
average color.
sampled image
Image Formation
continuous colors,
discrete locations.
discrete real-
valued image
Picture Element, Image Element, Pels, Pixel
it is the smallest unit of picture that can be
represented or controlled
the smallest addressable screen element in a
display divice;
each square is
called a pixel (for
picture element)
Image Enhancement
original + gamma - gamma + brightness - brightness
original + contrast - contrast histogram EQ histogram mod
Image is processed for visual interpretation
No general
theory
The viewer is the ultimate
judge of how well a
particular method works
Image enhancement
approaches
Spatial
Domain
Image Plane Itself
Direct Manipulation
Of Pixels In An
Image
Frequency
Domain
Frequency Plane
Modifying The
Fourier
Transform Of An
Image
Gray Level Transformations
-Linear Transformations
Negative and Identity transformations
Image with gray
levels in the range
[0,L-1]
The negative of the
image
s = (L-1) -r
Piecewise-Linear Transformation Functions
-Contrast stretching
Piecewise-Linear Transformation Functions
-Contrast stretching
The idea behind contrast stretching is
to increase the dynamic range of the
gray levels in the image being processed

If r1=s1 and r2=s2,
the transformation
is a linear function
that produces
no changes in gray
levels
Piecewise-Linear Transformation Functions
-Contrast stretching
If r1=r2, s1=0 and s2=L-1, the
transformation becomes a thresholding
function that creates a binary image.
Piecewise-Linear Transformation Functions
-Contrast stretching
If r1=r2, s1=0 and s2=L-1, the
transformation becomes a thresholding
function that creates a binary image.
Piecewise-Linear Transformation Functions
-Contrast stretching
Piecewise-Linear Transformation Functions
-Contrast stretching
Piecewise-Linear Transformation Functions
-Gray-level slicing
Highlights a specific range of grey levels
-Similar to thresholding
-Other levels can be suppressed or
maintained
-Useful for highlighting featuresin an
image
26
HISTOGRAM
imhist
36 36
22
Image 16x14 = 224 pixels
130
0 1 2 3
level
pixels

HISTOGRAM EQUALIZATION
-histeq


Question
Read a degraded image
Or
Read an image and change its brigthness
Plot its histogram using imhist()
Perform histogram equalization using histeq()
Plot its histogram using imhist()
Use subplot to show all the graph and pictures
Note :- also try to do the above steps by varying
contrast

Basics of Spatial Filtering

(x,y)
Image f(x,y)
Original Image
(x,y)
Image g(x,y)
Processed image
Example
Image f(x,y)
Original Image
4 4 3
3 50 1
2 2 3
1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9
The subimage is called a
filter, mask, kernel,
template, or window,
g(2,2)=(1/9)*4+(1/9)*4+(1/9)*3+
(1/9)*3+(1/9)*50+(1/9)*1+
(1/9)*2+(1/9)*2+(1/9)*3
=8
Example

Image f(x,y)
Processed image
8
Example

Image f(x,y)
Original Image
4 4 3
3 50 1
2 2 3
Example

Basics of Spatial Filtering

The subimage is called a
filter, mask, kernel,
template, or window,
The values in a filter
subimage are referred to
as coefficients, rather
than pixels.
Mechanics of spatial filtering
Assuming a 3 x 3 neighborhood, at
any point (x,y) in the image, the
response of the spatial filter is
Mechanics of spatial
filtering

Vector representation of
linear filtering

Spatial correlation and
convolution

Smoothing spatial filters
The output (response) of a smoothing,
linear spatial filter is simply the
average of the pixels contained in the
neighborhood of the filter mask.

averaging filters or lowpass filters.
used for blurring and noise reduction

Smoothing spatial filters

Sharpening spatial filters:
foundations

Using the second derivative for
image sharpening the Laplacian

Using the second derivative for
image sharpening the Laplacian

Question:- Spatial Filtering
Read an image(I)
Construct a mask
H=[1 1 1
1 1 1
1 1 1]
H=H/9
Use the function imfilter(I,H)


Question:- Spatial Filtering
Vary the size of the mask and do the
same
Ex:H=(1/25)*ones(5,5)
H=(1/81)*ones(9,9)
H=(1/400)*ones(20,20) etc


Also check the
difference between

Try .!

Using the second derivative for
image sharpening the Laplacian
Background features can be preserved
together with the sharpening effect of the
Laplacian by adding the Laplacian image to
the original.


Basics of filtering in the frequency
domain
To filter an image in the frequency domain:
1. Compute F(u,v) the DFT of the image
2. Multiply F(u,v) by a filter function H(u,v)
3. Compute the inverse DFT of the result

55
2-D DFT
2-D: x-axis then y-axis

=
+
=
1
0
1
0
) ( 2
) , (
1
) , (
N
y
M
x
y
M
v
x
M
u
j
e y x f
MN
v u F
t

=
+
=
1
0
1
0
) ( 2
) , ( ) , (
M
u
N
v
y
M
v
x
M
u
j
e v u F y x f
t
56
Complex Quantities to Real
Quantities
Useful representation
2 / 1 2 2
)] , ( ) , ( [ ) , ( v u I v u R v u F + =
]
) , (
) , (
[ tan ) , (
1
v u R
v u I
v u

= |
magnitude
phase
) , ( ) , ( ) , ( ) , (
2 2
2
v u I v u R v u F v u P + = =
Power spectrum

DFT Properties:
Periodicity
The DFT and its inverse are periodic
with period N




DFT Properties- Translation
Warning: to show a full period, we
need to translate the origin of the
transform at u=N/2 (or at
(N/2,N/2) in 2D)
|F(u-N/2)|
|F(u)|
DFT Properties:
Translation (contd)
no translation
after translation
62
Lowpass filters
Ideal Lowpass filters
Butterworth Lowpass filters
Gaussian Lowpass filters
Highpass filters
Homomorphic filters
Question:- Frequency Filtering- LP
Read an image(I)
Take the F T using fft2()
Perform fftshift of the above sequence
to make low frequency at the centre
Construct a mask with all elements zeros
Fill the centre portions with 1(for lowpass)
Perform element by element multiplication
Take the I F T using ifft2()
Convert the values using uint8() and show it

Question:- Frequency
Filtering- LP
Vary the mask inner size(1s positions)
try again

do some modifications
Read an image(I)
Take the F T using fft2()
Construct a mask with all elements zeros
Fill the centre portions with 1(for lowpass)
Perform fftshift of the mask
Perform element by element multiplication
Take the I F T using ifft2()
Convert the values using uint8() and show it

Is there any difference?
Construct a mask with all elements ones
Fill the centre portions with 0
(for high pass)

68
Ideal filters :

D(u,v) : distance from point (u,v) to the
original
D
0
: cutoff frequency
Ideal filter is nonphysical
Radially symmetric about the original


Lowpass filters

>
s
=
0
0
) , ( , 0
) , ( , 1
) , (
D v u D if
D v u D if
v u H

70
Lowpass filters ideal lowpass filter
71
Lowpass filters ideal lowpass filter


Butterworth Lowpass Filters
The transfer function of a Butterworth
lowpass filter of order n with cutoff
frequency at distance D
0
from the origin is
defined as:
n
D v u D
v u H
2
0
] / ) , ( [ 1
1
) , (
+
=
A Butterworth filter of order 1 has
no ringing. Ringing generally is
imperceptible in filters of order 2,
but can become a significant factor
in filters of higher order.
Butterworth Lowpass Filter
(cont)
Original
image
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
5
Result of
filtering with
Butterworth
filter of order 2
and cutoff radius
30
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
230
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
80
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
15
Butterworth Lowpass
Filter (cont)
Original
image
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
5
Butterworth Lowpass
Filter (cont)
Result of filtering
with Butterworth
filter of order 2
and cutoff radius
15
78
Lowpass filters Butterworth examples
Gaussian Lowpass Filters
The transfer function of a Gaussian
lowpass filter is defined as:
2
0
2
2 / ) , (
) , (
D v u D
e v u H

=
Gaussian Lowpass Filters
(cont)
Original
image
Result of
filtering with
Gaussian filter
with cutoff
radius 5
Result of
filtering with
Gaussian filter
with cutoff
radius 30
Result of
filtering with
Gaussian filter
with cutoff
radius 230
Result of
filtering with
Gaussian filter
with cutoff
radius 85
Result of
filtering with
Gaussian filter
with cutoff
radius 15
Lowpass Filters
Compared
Result of
filtering with
ideal low pass
filter of radius
15
Result of
filtering with
Butterworth
filter of order
2 and cutoff
radius 15
Result of
filtering with
Gaussian filter
with cutoff
radius 15
Lowpass Filtering
Examples
A low pass Gaussian filter is used to
connect broken text
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

Lowpass Filtering
Examples
Lowpass Filtering Examples
(cont)
Different lowpass Gaussian filters used to
remove blemishes in a photograph
Lowpass Filtering Examples
(cont)
Lowpass Filtering Examples
(cont)
Original
image
Gaussian lowpass
filter
Processed
image
Spectrum of
original image
Sharpening in the Frequency
Domain
Edges and fine detail in images are
associated with high frequency
components
High pass filters only pass the high
frequencies, drop the low ones
High pass frequencies are precisely
the reverse of low pass filters, so:
H
hp
(u, v) = 1 H
lp
(u, v)

Ideal High Pass Filters
The ideal high pass filter is given as:



where D
0
is the cut off distance as
before

>
s
=
0
0
) , ( if 1
) , ( if 0
) , (
D v u D
D v u D
v u H
Ideal High Pass Filters (cont)
Results of ideal
high pass
filtering with D
0

= 15
Results of ideal
high pass
filtering with D
0

= 30
Results of ideal
high pass
filtering with D
0

= 80
Butterworth High Pass Filters
The Butterworth high pass filter is
given as:



where n is the order and D
0
is the cut
off distance as before
n
v u D D
v u H
2
0
)] , ( / [ 1
1
) , (
+
=
Butterworth High Pass Filters
(cont)
Results of
Butterwort
h high pass
filtering of
order 2
with D
0
=
15
Results of
Butterwort
h high pass
filtering of
order 2
with D
0
=
80
Results of Butterworth high
pass filtering of order 2 with
D
0
= 30
Gaussian High Pass Filters
The Gaussian high pass filter is given
as:


where D
0
is the cut off distance as
before
2
0
2
2 / ) , (
1 ) , (
D v u D
e v u H

=
Gaussian High Pass Filters
(cont)
Results of
Gaussian
high pass
filtering
with D
0
=
15
Results of
Gaussian
high pass
filtering
with D
0
=
80
Results of Gaussian high
pass filtering with D
0
= 30
Highpass Filter Comparison
Results of ideal
high pass
filtering with D
0

= 15
Highpass Filter Comparison
Results of
Butterworth high pass
filtering of order 2
with D
0
= 15
Highpass Filter Comparison
Results of Gaussian
high pass filtering
with D
0
= 15
Highpass Filter Comparison
Results of ideal
high pass
filtering with D
0

= 15
Results of Gaussian
high pass filtering
with D
0
= 15
Results of
Butterworth high pass
filtering of order 2
with D
0
= 15
Highpass Filter Comparison
Results of ideal
high pass
filtering with D
0

= 15
Highpass Filter Comparison
Results of
Butterworth high pass
filtering of order 2
with D
0
= 15
Highpass Filter
Comparison
Results of Gaussian
high pass filtering
with D
0
= 15

Das könnte Ihnen auch gefallen