Image Processing Reference
In-Depth Information
Function edges=prewitt(image)
%derive edges by 3*3 Prewitt operator
%
%Usage: [new image]=prewitt(image)
%
%Parameters: image-array of points
%
%Author: Mark S. Nixon
%get dimensions
[rows, cols]=size(image);
%set the output image to black(0)
edges(1: rows,1:cols)=0;
for x=2: cols-1 %address all columns
except border
for y=2: rows-1 %address all rows
except border
%apply Mx template
x_mag=image (y-1, x-1)+image(y-1,x)...
+image(y-1, x+1)-image(y+1,x-1)-...
image(y+1, x)-image(y+1, x+1);
%apply My template
y_mag=image(y-1,x-1)+image(y,x-1)...
+image(y+1,x-1)-image(y-1, x+1)-...
image(y,x+1)-image(y+1,x+1);
%evaluate edge magnitude
edges(y,x,1)=sqrt((x_mag*x_mag)
+(y_mag*y_mag));
%evaluate edge direction
if x_mag==0
edges(y,x,2)=sign(y_mag)*1.5708;
else edges(y,x,2)=atan(y_mag/x_mag);
end
end
end
Eye edges by Roberts
cross operator
Magnitude of eye edges
by Prewitt operator
10
10
20
20
30
30
40
40
50
50
60
60
10 20 30 40 50 60
10 20 30 40 50 60
Magnitude of Prewitt edges (in comparison with Roberts)
plotedit on, title ('Magnitude of eye edges by Prewitt operator'),
plotedit off
subplot(1,2,2), imagesc(roberts_edges);
plotedit on, title ('Eye edges by Roberts cross operator'), plotedit
off
disp ('We can see that the effect of smoothing is to reduce noise in')
disp ('the edge detection process')
pause;
disp ('The direction is how the edge is changing, but this is much
less')
disp ('easy to see in the displayed image.')
direction=prewitt_edges(:,:,2);
imagesc(direction);
plotedit on, title ('Direction of eye edges by Prewitt operator'),
plotedit off
pause;
Search WWH ::




Custom Search