Documente Academic
Documente Profesional
Documente Cultură
CS 4487/9587
Ontario
A crash course on
The University of
Ontario
Point Processing
gamma correction window-center correction histogram equalization
Filtering
mean, Gaussian, and median filters image gradients
Extra Reading: Gonzales and Woods, Sec.3
The University of
Image processing
Ontario
An image processing operation typically defines a new image g in terms of an existing image f.
Examples:
The University of
Image processing
Ontario
An image processing operation typically defines a new image g in terms of an existing image f.
Examples:
We can transform either the domain or the range of f.
The University of
Image processing
Ontario
An image processing operation typically defines a new image g in terms of an existing image f.
Examples:
We can transform either the domain or the range of f.
( x, y ))
The University of
Image processing
Ontario
An image processing operation typically defines a new image g in terms of an existing image f.
Examples:
We can transform either the domain or the range of f.
( x, y ))
g ( x, y )
|u | |v|
h(u, v) f ( x u, y v) du dv
more on filtering later in the notes
The University of
Point Processing
Ontario
The simplest kind of range transformations are these independent of position (x,y) : g ( x, y ) t ( f ( x, y ))
for each original image intensity value I, function t() returns a transformed intensity value t(I).
This is called point processing. Important: every pixel is for himself spatial information is ignored! What can point processing do?
The University of
Point Processing:
Ontario
The University of
Point Processing:
Negative
Ontario
f ( x, y)
g ( x, y )
t(I )
255 I
g ( x, y) t ( f ( x, y)) 255 f ( x, y)
The University of
Point Processing:
Power-law transformations t
Ontario
The University of
Point Processing:
Gamma Correction
Ontario
The University of
Point Processing:
Ontario
The University of
Point Processing:
Ontario
Image Brightness
Image Contrast
probability of intensity i :
p(i )
ni n
The University of
Point Processing:
Contrast Stretching
Ontario
The University of
Point Processing:
Contrast Stretching
Original images Histogram corrected images
Ontario
1)
2)
The University of
Point Processing:
Contrast Stretching
Original images Histogram corrected images
Ontario
3)
4)
The University of
Histogram Equalization
Ontario
t (i )
j 0
p( j )
j 0
nj n
The University of
Point processing
Histogram Equalization
i i
Ontario
t (i )
j 0
p( j )
j 0
nj n
I=t(I) is a random variable with uniform distribution over its range [0,1]
That is, transform image I will have a uniformly-spread histogram (good contrast)
The University of
Point Processing:
Window-Center adjustment
Ontario
256
60000
The University of
Point Processing:
Window-Center adjustment
Ontario
256
60000
The University of
Point Processing:
Window-Center adjustment
256
Ontario
window
center
60000
The University of
Point Processing:
Window-Center adjustment
Ontario
The University of
Point Processing:
Window-Center adjustment
Ontario
The University of
Point Processing:
Window-Center adjustment
Ontario
The University of
Point Processing:
Window-Center adjustment
Ontario
The University of
Point Processing:
Window-Center adjustment
Ontario
The University of
Ontario
A: Its histogram wont change. No point processing will be affected Images contain a lot of spatial information
The University of
Ontario
A very general and useful class of transforms are the linear transforms of f, defined by a matrix M
The University of
Ontario
matrix M
The University of
Ontario
matrix M
The University of
Ontario
h [i]
k
[ a b c]
g [i]
u k
h [u ] f [i u ]
M f
The above allows negative filter indices. When you implement need to use: h[u+k] instead of h[u]
The University of
2D linear transforms
Ontario
f [i]
f [ i / m , i%m ]
The University of
2D filtering
Ontario
A 2D image f[i,j] can be filtered by a 2D kernel h[u,v] to produce an output image g[i,j]:
k k
g [i, j ]
u k v k
h [u, v] f [i u, j v]
h f
The University of
Ontario
A convolution operation is a cross-correlation where the filter is flipped both horizontally and vertically before being applied to the image:
k k
g [i, j ]
u k v k
h [u, v] f [i u, j v]
It is written:
h f
u
k k v
h[ u, v] f [i u, j v]
k
Suppose h is a Gaussian or mean kernel. How does convolution differ from cross-correlation?
If
h[u, v]
The University of
2D filtering
Noise
Filtering is useful for noise reduction...
(side effects: blurring)
Common types of noise: Salt and pepper noise: random occurrences of black and white pixels Impulse noise: random occurrences of white pixels Gaussian noise: variations in intensity drawn from a Gaussian normal distribution
Ontario
The University of
Ontario
100 130 110 120 110 130 100 90 0 110 0 130 110 120 100 0 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
The University of
Mean filtering
0 0 0 0 0 0 0 0 0 0
Ontario
0
0 0
0
0 0
0
0 0
0 90 90 90 90 90 0 0 90 90 90 90 90 0
0
0 0
0
0 0
0 90 90 90 90 90 0
0 90 0 90 90 90 0 0 90 90 90 90 90 0
0
0 0
0
0 0
0
0
0
0
0
0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0 90 0
The University of
Mean filtering
0 0 0 0 0 0 0 0 0 0
Ontario
0
0 0
0
0 0
0
0 0
0 10 20 30 30 30 20 10 0 20 40 60 60 60 40 20 0 30 60 90 90 90 60 30 0 30 50 80 80 90 60 30 0 30 50 80 80 90 60 30 0 20 30 50 50 60 40 20 10 20 30 30 30 30 20 10 10 10 10 0 0 0 0 0
0 90 90 90 90 90 0 0 90 90 90 90 90 0
0
0 0
0
0 0
0 90 90 90 90 90 0
0 90 0 90 90 90 0 0 90 90 90 90 90 0
0
0 0
0
0 0
0
0
0
0
0
0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0 90 0
The University of
Ontario
The University of
Mean kernel
Ontario
0
0 0
0
0 0
0
0 0
0 90 90 90 90 90 0 0 90 90 90 90 90 0
0
0 0
0
0 0
0 90 90 90 90 90 0
0 90 0 90 90 90 0 0 90 90 90 90 90 0
0
0 0
H [u, v]
0
0 0
0
0
0
0
0
0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0 90 0
F [ x, y ]
The University of
Gaussian Filtering
Ontario
A Gaussian kernel gives less weight to pixels 0 0 0 0 0 0 0 0 0 0 further from the center 0 0 0 0 0 0 0 0 0 0 of the window
0 0 0 0 0 90 90 90 90 90 0 0 90 90 90 90 90 0 0 0
0
0 0
0
0 0
0 90 90 90 90 90 0
0 90 0 90 90 90 0 0 90 90 90 90 90 0
0
0 0
1 16
1 2 1
2 4 2
1 2 1
H [u, v]
0
0 0
0
0
0
0
0
0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0
0
0 0 This kernel is an approximation of a Gaussian function:
0 90 0
F [ x, y ]
The University of
Ontario
The University of
Median filters
Ontario
A Median Filter operates over a window by selecting the median intensity in the window. What advantage does a median filter have over a mean filter?
The University of
Ontario
The University of
Ontario
The University of
Ontario
Recall
lim
0
f (x
, y) f ( x, y)
x
f ( xi 1 , y) f ( xi 1 , y) 2 x
x
Now this is linear and shift invariant, so must be the result of a convolution.
f (convolution)
1 2 x
0 0 0 1 0 -1 0 0 0
x
with kernel
[u, v]
sometimes this may not be a very good way to do things, as we shall see
The University of
Ontario
Recall
lim
0
f (x
, y) f ( x, y)
x
f ( xi 1 , y) f ( xi 1 , y) 2 x
x
Now this is linear and shift invariant, so must be the result of a convolution.
f (convolution)
1 2 x
0 0 0 1 0 -1 0 0 0
x
with kernel
[u, v]
sometimes this may not be a very good way to do things, as we shall see
The University of
Finite differences
Ontario
The University of
Ontario
The University of
Ontario
What is to be done?
intuitively, most pixels in images look quite a lot like their neighbours this is true even at an edge; along the edge theyre similar, across the edge theyre not suggests that smoothing the image should help, by forcing pixels different to their neighbours (=noise pixels?) to look more like neighbours
The University of
Ontario
Issue: noise smooth before differentiation two convolutions: smooth, and then differentiate? actually, no - we can use a derivative of Gaussian filter because differentiation is convolution, and convolution is associative x ( H f ) ( x H ) f
The University of
H) f
Ontario
The University of
Ontario
f
1 8 y
1 8 x
1 0 -1
1 2 1
0 0 0 -1 -2 -1
y
2 0 -2
1 0 -1
x
[u, v]
[u, v]
The University of
Image Gradients
Ontario
x
f x
f f
y
f y
( fx ) 2 ( fy ) 2
f )2 (
f )2
The direction of the gradient corresponds to the direction of the steepest ascend - normally gradient is orthogonal to object boundaries in the image.
The University of
Ontario
Equivalently, gradient of function f ( p) 2 at point p R can be defined as a vector f s.t. for any unit vector n
Gradient at point p
( f n)
f n
f (p
n ) f ( p)
dot product
Pure vector algebra, specific coordinate system is irrelevant Works for functions of 2-, 3-, or larger number of variables Previous slide gives you a specific way for computing coordinates of vector
( , )
f x
f y
The University of
Image Gradient
Ontario
Typical application where image gradients are used is image edge detection
find points with large image gradients
The University of
f)
Ontario
f
2
f
2
x y
f
divergence of gradient
0 0 0 -1 2 -1 0 0 0
0 -1 0 0 2 0
0 -1 0 -1 4 -1 0 -1 0
0 -1 0
The University of
f)
Ontario
f
2
f
2
x y
f
divergence of gradient
http://homepages.inf.ed.ac.uk/rbf/HIPR2/zeros.htm
Laplacian (2nd derivative) of the image along the same scan line
The University of
Ontario
G
LoG( x, y )
LoG
1
4
y
2
x2 y2 2 2
fspecial
http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
The University of
Ontario
LoG
http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
The University of
Unsharp masking
Ontario
I G*I
=
unsharp mask
+
unsharp mask
The University of
Unsharp masking
Ontario
(1
)I
G*I
[(1
)G
1
1 2
G 2] *I
I G*I
unsharp mask I U
+
unsharp mask
The University of
Unsharp masking
MATLAB
Imrgb = imread(file.jpg); im = im2double(rgb2gray(imrgb)); g= fspecial('gaussian', 25,4); imblur = conv2(im,g,same'); imagesc([im imblur]) imagesc([im im+.4*(im-imblur)])
Ontario
unsharp mask kernel can be seen as a difference of two Gaussians (DoG) with 1 2 .
http://homepages.inf.ed.ac.uk/rbf/HIPR2/unsharp.htm
DoG
G1 G
LoG
The University of
Ontario
Applying a filter at some point can be seen as taking a dot-product between the image and some vector Filtering the image is a set of dot products
Insight
filters may look like the effects they are intended to find filters find effects they look like
The University of
Normalized cross-correlation
Ontario
Tricks:
ensure that filter has a zero response to a constant region (helps reduce response to irrelevant background) subtract image average when computing the normalizing constant (i.e. subtract the image mean in the neighbourhood) absolute value deals with contrast reversal
The University of
Ontario
The University of
Ontario