Professional Documents
Culture Documents
Page 1
Lecture notes
Introduction
Edges contain the most useful information in an image.
In an image, an edge is a curve that follows a path of rapid
change in image intensity.
Edges are often associated with the boundaries of objects in a
scene.
We may use edges
to measure the size of objects in an image;
to isolate particular objects from their background;
to recognize or classify objects.
Jorma Kekalainen
859
Edge-finding algorithms
There are a large number of edge-finding
algorithms, and we shall look at some of the most
straightforward of them.
Here, we shall show how to create edge images
using basic filtering methods, and discuss the
Matlab edge function.
The general Matlab command for finding edges is
edge(image,'method',parameters. . . )
where the available parameters depend on the
method used.
Jorma Kekalainen
860
Page 2
Lecture notes
Definition of edge
An edge may be loosely defined as a line of pixels showing an
observable difference.
For example, consider the two blocks of pixels
861
Edges
Suppose we follow the gray values of pixels in a line
crossing an edge, as illustrated below.
862
Page 3
Lecture notes
A ramp edge
A line
Jorma Kekalainen
A roof
863
Differences
If we now plot the differences between each gray
value and its predecessor from the ramp edge, we
would obtain a graph
Differences of the edge function
864
Page 4
Lecture notes
Jorma Kekalainen
865
Different differences
We can define the difference in three separate
ways:
the forward difference:
the backward difference:
the central difference:
Jorma Kekalainen
866
Page 5
Lecture notes
Generalized differences
An image is a function of two variables, so we
must generalize those definitions to include
both the x and y values
Jorma Kekalainen
867
868
Page 6
Lecture notes
Jorma Kekalainen
869
Prewitt filter Px
Both of the previous filters can be applied at once
convolving them.
As a result of convolution we get a combined filter:
>> Px=conv2(A,B,'same')
Px =
-1 0 1
-1 0 1
870
-1 0 1
Page 7
Lecture notes
Jorma Kekalainen
871
0 -1 0
0 0 0
0 1 0
Digital Image Processing
872
Page 8
Lecture notes
0
0
0
0
1
0
0
1
0
873
Prewitt filter Py
Both of the previous filters can be applied at
once convolving them.
As a result of convolution we get a combined
filter:
A =
0 -1
0 0
0 1
B' =
0
1
0
0
0
0
0 0
1 1
Jorma Kekalainen
0 0
>> Py=conv2(A',B','same')
Py =
-1 -1 -1
0 0 0
874
1 1 1
Page 9
Lecture notes
Note
>> A=[0 0 0;-1 0 1;0 0 0]
A=
0 0 0
-1 0 1
0 0 0
>> B=[0 1 0;0 1 0;0 1 0]
B=
0 1 0
0 1 0
0 0
0 1 0
1 1
>> Px=conv2(A,B,'same')
0 0
Px =
-1 0 1
0 0
-1 0 1
1 1
-1 0 1
0 0
>> Py=conv2(A',B','same')
Py =
-1 -1 -1
0 0 0
Digital Image Processing 1
1 1
0
0
0
0
0
0
Jorma Kekalainen
>> B'
ans =
0
1
0
0
1
0
875
Prewitt filters
Filter for finding vertical edges
876
Page 10
Lecture notes
Note
If we change increasing directions in the function array just
the opposite we correspondingly get matrices flilr(Px) and
flipud(Py)
1
1
1
Py =
-1 -1 -1
0 0 0
1 1 1
>> fliplr(Px)
ans =
1 0 -1
1 0 -1
1 0 -1
>>flipud(Py)
ans =
1 1 1
0 0 0
-1 -1 -1
Px =
-1
-1
-1
0
0
0
Flipud flip matrix up to down and Fliplr flip matrix left to right.
Jorma Kekalainen
877
Note
h = fspecial('prewitt') returns the 3-by-3 filter
h=[ 1 1 1; 0 0 0; -1 -1 -1 ]
that emphasizes horizontal edges by approximating a
>> fspecial('prewitt')
vertical gradient.
ans =
1 1 1
0 0 0
-1 -1 -1
878
Page 11
Lecture notes
Jorma Kekalainen
879
Example
Let us take the image of
the integrated circuit ,
which can be read into
Matlab with
>> ic=imread('ic.tif');
Applying each of Px and
Py individually provides
the results shown in the
following slice
Jorma Kekalainen
An original image
880
Page 12
Lecture notes
Example
After filtering with the Prewitt filters
Figure (a)
Jorma Kekalainen
Figure (b)
881
Example
Figure (a) was produced with the following Matlab
commands:
px=[-1 0 1;-1 0 1;-1 0 1];
icx=filter2(px,ic);
figure,imshow(icx/255)
and figure (b) with
py=px';
icy=filter2(py,ic);
figure,imshow(icy/255)
Note that the filter Px highlights vertical edges, and Py
horizontal edges.
Jorma Kekalainen
882
Page 13
Lecture notes
Example
%Edge detection
ic=imread('ic.tif');
figure,imshow(ic)
title('Original image ic.tif')
%
px=[-1 0 1;-1 0 1;-1 0 1];
icx=filter2(px,ic);
figure,imshow(icx/255)
title('Vertical edges in ic.tif')
%
py=px';
icy=filter2(py,ic);
figure,imshow(icy/255)
title('Horizontal edges in ic.tif')
%
% All the edges with:
edge_p=sqrt(icx.^2+icy.^2);
figure,imshow(edge_p/255)
title('All edges in the gray-scale image ic.tif')
Jorma Kekalainen
883
Example
>> %
level=graythresh(ic)
BW=im2bw(ic,level);
figure,imshow(BW)
title('Binary image thresholded from ic.tif using graythresh leveling')
xlabel(['Threshold level= ',num2str(level)])
level =
0.6784
Jorma Kekalainen
884
Page 14
Lecture notes
Example
>> edge_th=im2bw(edge_p/255,graythresh(edge_p));
figure,imshow(edge_th)
title('Binary image thresholded after Prewitt process using graythresh
leveling')
xlabel(['Threshold level=',num2str(graythresh(edge_p))])
%
Jorma Kekalainen
885
Example
We can create a figure containing all the edges with:
edge_p=sqrt(icx.^2+icy.^2);
figure,imshow(edge_p/255)
This is a gray-scale image; a binary image containing
edges only can be produced by thresholding.
edge_t=im2bw(edge_p/255,0.3);
>> whos('edge_p','edge_t')
Name
Size
Bytes Class Attributes
edge_p 256x256
524288 double
Jorma Kekalainen
edge_t
256x256
65536 logicalDigital Image Processing
886
Page 15
Lecture notes
Example
Jorma Kekalainen
887
Note
We can obtain edges by the Prewitt filters directly by
using the command
>> edge_p=edge(ic,'prewitt');
and the edge function takes care of all the filtering, and
of choosing a suitable threshold level.
The result is shown in the following figure.
Note that the previous figure and the next figure seem
different to each other.
This is because the edge function does some extra
processing besides taking the square root of the sum of
the squares of the filters.
Jorma Kekalainen
Image Processing
Note:
See the help text of theDigital
edge
function for more information.888
Page 16
Lecture notes
Example
%We can obtain edges by the Prewitt filters directly by using the command
edge_p=edge(ic,'prewitt');
figure, imshow(edge_p)
title('Edges of ic.tif directly by using the Prewitt filters')
xlabel('Using command edge(ic,''prewitt'');')
Jorma Kekalainen
889
Sobel filters
The Sobel filters are similar to the Prewitt filters, in that they
apply a smoothing filter in the opposite direction to the
central difference filter.
Now the smoothing takes the form which gives slightly more
prominence to the central pixel
0
1
0
Jorma Kekalainen
0
2
0
0
1
0
0
0
0
1
2
1
0
0
0
890
Page 17
Lecture notes
Sobel filter Sx
As we previously notice in Prewitts case this filter
1
2
1
0
0
0
891
Sobel filter Sx
Both of the previous filters can be applied at once
convolving them.
As a result of convolution we get a combined filter:
Sx =
>> Sx=conv2(A,B','same')
Sx =
-1 0 1
-2 0 2
892
-1 0 1
Page 18
Lecture notes
Sobel filter Sy
As we previously notice in Prewitts case this filter
0 -1
0 0
0 1
0
0
0
0
2
0
0
1
0
893
Sobel filter Sy
Both of the previous filters can be applied at once
convolving them.
As a result of convolution we get a combined filter:
Sy =
Sy will find horizontal edges in an image.
>> Sx=conv2(A,B','same')
Sx =
-1 0 1
-2 0 2
Jorma Kekalainen
-1 0 1
Sy=Sx'=(conv2(A,B','same'))'
Sy =
-1 -2 -1
0 0 0
894
1 2 1
Page 19
Lecture notes
Sobel filters
Filter for finding vertical edges
Sx =
and its companion for finding horizontal edges
Sy =
are the Sobel filters for edge detection.
Jorma Kekalainen
895
Note
If we change increasing directions in the function array just
the opposite we correspondingly get matrices flilr(Sx) and
flipud(Sy)
Sx =
-1
-2
-1
1
2
1
Sy =
-1 -2 -1
0 0 0
1 2 1
>> fliplr(Sx)
ans =
1 0 -1
2 0 -2
1 0 -1
>> flipud(Sy)
ans =
1 2 1
0 0 0
-1 -2 -1
0
0
0
Flipud flip matrix up to down and Fliplr flip matrix left to right.
Jorma Kekalainen
896
Page 20
Lecture notes
fspecial('sobel')
h = fspecial('sobel') returns a 3-by-3 filter
h =[ 1 2 1; 0 0 0; -1 -2 -1 ]
that emphasizes horizontal edges using the
smoothing effect by approximating a vertical
gradient.
If you need to emphasize vertical edges,
transpose the filter h'.
Jorma Kekalainen
h=
1 2 1
0 0 0
-1 -2 -1
h=h' =
1 0 -1
2 0 -2
897
1 0 -1
Example
edge_r=edge(ic,'roberts');
figure,imshow(edge_r)
edge_s=edge(ic,'sobel');
figure,imshow(edge_s)
Of the three filters, the Sobel filters are probably the best; they provide good edges,
and they
perform reasonably well in Digital
the presence
of noise.
Jorma Kekalainen
Image Processing
898
Page 21
Lecture notes
Example
Jorma Kekalainen
899
Example
Jorma Kekalainen
900
Page 22
Lecture notes
Difference of differences
Another class of edge-detection method is
obtained by considering the difference of
differences.
These are called second differences.
E.g.,
x2 = x x f ( x, y )
y2 = y y f ( x, y )
Jorma Kekalainen
902
Page 23
Lecture notes
Note
We can define the difference in three separate
ways:
the forward difference:
the backward difference:
the central difference:
Jorma Kekalainen
903
Note
An image is a function of two variables, so we
must generalize those definitions to include
both the x and y values
Jorma Kekalainen
904
Page 24
Lecture notes
Example
x2 = x x f ( x, y ) = x [ f ( x + 1, y ) f ( x, y )]
= [ f ( x + 1, y ) f ( x, y )] [ f ( x, y ) f ( x 1, y )]
= f ( x + 1, y ) 2 f ( x, y ) + f ( x 1, y )
Jorma Kekalainen
905
x2 = x x f ( x, y ) = x [ f ( x + 1, y ) f ( x, y )]
= [ f ( x + 1, y ) f ( x, y )] [ f ( x, y ) f ( x 1, y )]
= f ( x + 1, y ) 2 f ( x, y ) + f ( x 1, y )
The corresponding filter for second differences x2 in the x
direction can be implemented by the filter:
Jorma Kekalainen
906
Page 25
Lecture notes
y2 = y y f ( x, y ) = y [ f ( x, y + 1) f (x, y )]
= [ f ( x, y + 1) f (x, y )] [ f ( x, y ) f ( x, y 1)]
= f ( x, y + 1) 2 f ( x, y ) + f ( x, y 1)
The corresponding filter for second differences y2 in the y
direction can be implemented by the filter
Jorma Kekalainen
907
Laplacian filter
The corresponding filters for second differences x2 in the x
direction and for second differences y2 in the y direction are
Jorma Kekalainen
908
Page 26
Lecture notes
Example
Take the pixel values describing a ramp edge
Jorma Kekalainen
909
Laplacian
We see that the Laplacian (after taking an
absolute value, or squaring) gives double
edges.
It is also extremely sensitive to noise.
However, the Laplacian does have the
advantage of detecting edges in all directions
equally well.
Jorma Kekalainen
910
Page 27
Lecture notes
Example
Suppose we enter the Matlab commands:
l=fspecial('laplacian',0);% Basic laplacian mask
ic_l=filter2(l,ic);
figure,imshow(mat2gray(ic_l))
The result of which is shown in the following
figure.
Jorma Kekalainen
911
Example
%
ic=imread('ic.tif');
figure,imshow(ic)
title('Original image ic.tif')
%
L=fspecial('laplacian',0);
ic_L=filter2(L,ic);
figure,imshow((ic_L))
title('Filtering by discrete Laplacian')
xlabel('fspecial(''laplacian'',0)')
%
Jorma Kekalainen
912
Page 28
Lecture notes
Jorma Kekalainen
913
914
Page 29
Lecture notes
fspecial('laplacian', alpha)
fspecial('laplacian', alpha) returns a 3-by-3
filter approximating the shape of the twodimensional Laplacian operator.
The parameter alpha controls the shape of the
Laplacian and must be in the range 0.0 to 1.0.
The default value for alpha is 0.2.
Jorma Kekalainen
915
fspecial('laplacian', alpha)
>> fspecial('laplacian',1.0)
ans =
0.5000
0 0.5000
0 -2.0000
0
0.5000
0 0.5000
>> fspecial('laplacian',0.9)
ans =
>> fspecial('laplacian',0.8)
ans =
>> fspecial('laplacian',0.7)
ans =
>> fspecial('laplacian',0.6)
ans =
>> fspecial('laplacian',0.5)
ans =
>> fspecial('laplacian',0.4)
ans =
0.2857 0.4286 0.2857
0.4286 -2.8571 0.4286
0.2857 0.4286 0.2857
>> fspecial('laplacian',0.3)
ans =
0.2308 0.5385 0.2308
0.5385 -3.0769 0.5385
0.2308 0.5385 0.2308
>> fspecial('laplacian',0.2)
ans =
0.1667 0.6667 0.1667
0.6667 -3.3333 0.6667
0.1667 0.6667 0.1667
>> fspecial('laplacian',0.1)
ans =
0.0909 0.8182 0.0909
0.8182 -3.6364 0.8182
0.0909 0.8182 0.0909
>> fspecial('laplacian',0.0)
ans =
0 1 0
1 -4 1
0 1 0
default value
alpha=0.2
916
Page 30
Lecture notes
Zero crossings
A more appropriate use for the Laplacian is to find the
position of edges by locating zero crossings.
If we look at figure below, we see that the position of the
edge is given by the place where the value of the filter takes
on a zero value.
In general, these are places where the result of the filter
changes sign.
Jorma Kekalainen
917
Jorma Kekalainen
Filtered image
Zero crossings are inside red rectangles
918
Page 31
Lecture notes
Example
Zero crossings are inside red circles
Jorma Kekalainen
919
Example
To give an indication of the
way zero-crossings work,
look at the edge plots and
their second differences.
In each case the zerocrossing is circled.
The important point is to
note that across any edge
there can be only one zerocrossing.
Thus an image formed from
zero-crossings has the
potential to be very handy.
Jorma Kekalainen
920
Page 32
Lecture notes
50
50
50
50
50
50
50
50
50
50
50
50
200
200
200
200
50
50
50
50
-100 -50 -50 -50 -50 -50 -50 -50 -50 -100
50 50 50 50 50 50 50
-50 0 150 150 150 150 150 150 0 -50
50 50 50 50 50 50 50
200 200 200 200 200 50 50 -50 150 -300 -150 -150 -150 -150 -300 150 -50
200 200 200 200 200 50 50 -50 150 -150 0 0 0 0 -150 150 -50
200 200 200 200 200 50 50 -50 150 -150 0 0 0 0 -150 150 -50
200 200 200 200 200 50 50 -50 150 -300 -150 0 0 0 -150 150 -50
-50 0 150 300 -150 0 0 -150 150 -50
50 200 200 200 200 50 50
-50 0 0 150 -300 -150 -150 -300 150 -50
50 200 200 200 200 50 50
-50 0 0 0 150 150 150 150 0 -50
50 50 50 50 50 50 50
-100 -50 -50 -50 -50 -50 -50 -50 -50 -100
50 50 50 50 50 50 50
Jorma Kekalainen
921
922
Page 33
Lecture notes
Marr-Hildreth method
As we saw previously far too many gray level changes have
been interpreted as edges by that method.
To eliminate this problem, we may first smooth the image
with a Gaussian filter.
This leads to the following sequence of steps for edge
detection called Marr-Hildreth method:
1. smooth the image with a Gaussian filter,
2. convolve the result with a laplacian,
3. find the zero crossings.
Jorma Kekalainen
923
Marr-Hildreth method
This method was designed to provide an edge detection method to
be as close as possible to biological vision.
The first two steps (smooting and convolving) can be combined
into one, to produce a Laplacian of Gaussian (LoG) or 'log' filter.
These filters can be created with the fspecial function.
If no extra parameters are provided to the zerocross edge option,
then the filter is chosen to be the LoG filter found by
fspecial('log',13,2)
This means that the following command:
edge(ic,'log');
produces exactly the same result as the commands:
log=fspecial('log',13,2);
edge(ic,'zerocross',log);
Jorma Kekalainen
924
Page 34
Lecture notes
925
Marr-Hildreth method
In fact the LoG and
zerocross options
implement the same edge
finding method; the
difference being that the
zerocross option allows
us to specify our own
filter.
The result after applying
an LoG filter and finding
its zero crossings is given
in figure beside
Jorma Kekalainen
926
Page 35
Lecture notes
Marr-Hildreth method
log=fspecial('log',13,2);
edge(ic,'zerocross',log);
Jorma Kekalainen
edge(ic,'log');
927
Edge detection
In an image, an edge is a curve that follows a path of rapid
change in image intensity.
Edges are often associated with the boundaries of objects in a
scene.
Edge detection is used to identify the edges in an image.
To find edges, we can use the edge function.
This function looks for places in the image where the intensity
changes rapidly, using one of these two criteria:
Places where the first derivative of the intensity is larger in magnitude
than some threshold
Places where the second derivative of the intensity has a zero crossing
Jorma Kekalainen
928
Page 36
Lecture notes
Note
There are a a vast number of different edge detection algorithms
and methods.
As to which method is the best; like so many image processing
tasks, this is highly subjective.
The choice of an suitable edge detector will depend very much on
the nature of the image, the amount (and type) of noise, and the
use for which the edges are to be put.
The edge function provides a number of derivative estimators.
The most powerful edge-detection method that Matlabs edge
function provides is the Canny method.
The Canny method differs from the other edge-detection methods
in that it uses two different thresholds (to detect strong and weak
edges), and includes the weak edges in the output only if they are
connected to strong edges.
This method is therefore less likely than the others to be fooled by
noise, and more likely to detect true weak edges.
Jorma Kekalainen
929
Example
I = imread('coins.png');
figure,imshow(I)
>> BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
figure;
imshowpair(BW1,BW2,'montage')
title('Sobel Filter
Canny Filter');
Jorma Kekalainen
930
Page 37
Lecture notes
Exercise
Construct the next matrix image using matrix operations
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
200
200
200
200
50
50
50
50
50 50 50 50 50 50 50
50 50 50 50 50 50 50
200 200 200 200 200 50 50
200 200 200 200 200 50 50
200 200 200 200 200 50 50
200 200 200 200 200 50 50
50 200 200 200 200 50 50
50 200 200 200 200 50 50
50 50 50 50 50 50 50
50 50 50 50 50 50 50
931
Solution
>> B=50*ones(10)
B=
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
>> B(3:8,3:8)=200*ones(6)
B=
50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50
50 50 200 200 200 200 200 200
50 50 200 200 200 200 200 200
50 50 200 200 200 200 200 200
50 50 200 200 200 200 200 200
50 50 200 200 200 200 200 200
50 50 200 200 200 200 200 200
50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50
>> B(7:8,3:4)=50*ones(2)
B=
50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
50 50 200 200 200 200 200 200 50 50
50 50 200 200 200 200 200 200 50 50
50 50 200 200 200 200 200 200 50 50
50 50 200 200 200 200 200 200 50 50
50 50 50 50 200 200 200 200 50 50
50 50 50 50 200 200 200 200 50 50
50 50 50 50 50 50 50 50 50 50
Jorma Kekalainen
Digital Image Processing
50 50 50 50 50 50 50 50 50 50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
B=100*ones(10)
B(3:8,3:8)=200*ones(6)
B(7:8,3:4)=100*ones(2)
l=fspecial('laplacian',0);
B_L=filter2(l,B)
932
Page 38
Lecture notes
Solution
l=fspecial('laplacian',0);
B_L=filter2(l,B)
B_L =
-100 -50 -50 -50 -50 -50 -50 -50 -50 -100
-50 0 150 150 150 150 150 150 0 -50
-50 150 -300 -150 -150 -150 -150 -300 150 -50
-50 150 -150 0 0 0 0 -150 150 -50
-50 150 -150 0 0 0 0 -150 150 -50
-50 150 -300 -150 0 0 0 -150 150 -50
-50 0 150 300 -150 0 0 -150 150 -50
-50 0 0 150 -300 -150 -150 -300 150 -50
-50 0 0 0 150 150 150 150 0 -50
-100 -50 -50 -50 -50 -50 -50 -50 -50 -100
Jorma Kekalainen
933
Page 39
Lecture notes
Edge enhancement
Previously we have seen how to isolate edges
in an image.
A related operation is to make edges in an
image slightly sharper, which generally results
in an image more pleasing to the human eye.
The operation is called edge enhancement, or
unsharp masking.
This last term comes from the printing
industry.
Jorma Kekalainen
935
Idea of unsharp
The idea of unsharp masking is to subtract a scaled unsharp
version of the image from the original.
In practice, we can achieve this affect by subtracting a scaled
blurred image from the original.
The schema for unsharp masking
Jorma Kekalainen
936
Page 40
Lecture notes
Example
Suppose we have an image x of type uint8, then we can apply
unsharp masking by the following sequence of commands:
f=fspecial('average');
xf=filter2(f,x);
xu=double(x)-xf/1.5;% scale k=1/1.5<1
imshow(xu/70)
The last command scales the result so that imshow displays
an appropriate image; the value may need to be adjusted
according to the input image.
Jorma Kekalainen
937
Example
%Unsharp masking
%Suppose we have an image C of type uint8. Then we can apply
%unsharp masking by the following sequence of commands:
%
C=imread('cameraman.tif');
figure, imshow(C)
title('Original image')
f=fspecial('average');
Cf=filter2(f,C);
Cu=double(C)-Cf/1.5;
figure, imshow(Cu/70)
title('Unsharp masking with 3*3 averaging filter')
Jorma Kekalainen
938
Page 41
Lecture notes
Example
Suppose that C is the image shown in figure(a), then the result
of unsharp masking is given in figure (b).
The result appears to be a better image than the original; the
edges are sharper and more clearly defined.
(a) Original image
Jorma Kekalainen
939
Unsharp masking
To see why this unsharp
masking works, we may
consider the function of
gray values as we travel
across an edge, as shown
in graph (a).
As a scaled (k<1) blur is
subtracted from the
original, the result is that
the edge is enhanced, as
shown in graph (c).
Jorma Kekalainen
940
Page 42
Lecture notes
941
Jorma Kekalainen
942
Page 43
Lecture notes
Jorma Kekalainen
943
Exercise
Verify with Matlab the previous equality
Jorma Kekalainen
944
Page 44
Lecture notes
Solution
Verify with Matlab the previous equality
>> B=-3*1/9*ones(3)
B=
-0.3333 -0.3333 -0.3333
-0.3333 -0.3333 -0.3333
>> C=1/3*[-1,-1,-1;-1,11,-1;-1,-1,-1]
-0.3333 -0.3333 -0.3333
C=
>> A+B
-0.3333 -0.3333 -0.3333
ans =
-0.3333 3.6667 -0.3333
-0.3333 -0.3333 -0.3333
-0.3333 -0.3333 -0.3333
-0.3333 3.6667 -0.3333
Jorma Kekalainen
Digital Image Processing
-0.3333 -0.3333 -0.3333
945
Example
Figure below was created using the Matlab commands
p=imread('cameraman.tif');
u=fspecial('unsharp',0.5);
pu=filter2(u,p);
imshow(p),figure,imshow(pu/255)
Original
Jorma Kekalainen
Page 45
Lecture notes
Jorma Kekalainen
947
Jorma Kekalainen
948
Page 46
Lecture notes
Example
C=imread('cameraman.tif');
figure, imshow(C)
title('Original image')
f=[-1 -1 -1;-1 11 -1;-1 -1 -1]/9;
Cf=filter2(f,C);
figure, imshow(Cf/90)
title('Filtering very similar to the unsharp filter above, except
for a scaling factor')
xlabel('Coefficient 1/90 was obtained by trial and error')
Jorma Kekalainen
949
Example
Jorma Kekalainen
950
Page 47
Lecture notes
Note
We can also write the high boost formula above as
Jorma Kekalainen
951
If we take A=5/6
Jorma Kekalainen
952
Page 48
Lecture notes
953
hb1=3*id-2*f
hb2=1.25*id-0.25*f
hb1 =
-0.2222 -0.2222 -0.2222
-0.2222 2.7778 -0.2222
-0.2222 -0.2222 -0.2222
hb2 =
-0.0278 -0.0278 -0.0278
-0.0278 1.2222 -0.0278
-0.0278 -0.0278 -0.0278
954
Page 49
Lecture notes
Example
If each of the filters hb1 and hb2 are applied to an image with filter2, the
result will have enhanced edges.
The images were obtained with
x1=filter2(hb1,x);
x2=filter2(hb1,x);
imshow(x2/255)
imshow(x1/255)
Jorma Kekalainen
hb1 appears
to produce the
best result;
hb2 produces
an image not
very much
sharper than
955
the original.
Page 50