
Image Segmentation 253
MATLAB/Octave
>> s = im2double(imread(’stairs.png’));
>> [r,c] = size(s);
>> dirs = [1 1;1 0;-1 0;0 1;0 -1;-1 -1;1 -1;-1 1];
>> sp = padarray(s,[1,1]);
>> z = zeros(r+2,c+2,8);
>> w = zeros(r+2,c+2,8);
>> for i = 1:8
> z(2+dirs(i,1):1+dirs(i,1)+r,2+dirs(i,2):1+dirs(i,2)+c,:) = s;
> w(:,:,i) = imfilter((z(:,:,i)-sp).^2,ones(3,3));
> end
>> corners = min(w,3);
To show the corners, create an image that includes a darkened version of the original added
to a brightened version of the corners array:
MATLAB/Octave
>> imshow(s/4+4
*
corners(2:r+1,2:c+1))
and the result is shown in Figure 9.33.
FIGURE 9.33: Moravec corner detection
Python has a
corner ...