I implemented the Prewitt edge detector and compared my output with Matlab's in-built Prewitt edge detector and I noticed that my output gave thicker edges. What could be the reason?
input = imread('pic.png');
input = double(rgb2gray(input));
kernel_x = [-1, 0, 1; -1, 0, 1; -1, 0, 1];
kernel_y = [1, 1, 1; 0, 0, 0; -1, -1, -1];
[length, width] = size(input);
new = input;
for i = 1:length - 2
for j = 1:width - 2
Gx = sum(sum(kernel_x.*input(i:i 2, j:j 2)));
Gy = sum(sum(kernel_y.*input(i:i 2, j:j 2)));
new(i 1, j 1) = sqrt(Gx.^2 Gy.^2);
end
end
new = uint8(new);
% binarizing image and setting threshold
edge = imbinarize(edge, 100); % final output from implementation
The in-built function I used is edge(input, 'Prewitt')
Output from my implementation vs the in-built operator:
What could be the reason for this?
I tried changing the Threshold value also but still no luck.
CodePudding user response:
It is not clearly stated in the documentation, but for the Sobel, Prewitt and Roberts methods, edge
applies a thinning. There is an optional input argument 'nothinning'
, which skips the thinning step. Unfortunately this is the only bit in the documentation that indicates that this step is happening.
You can apply a thinning if you have the Image Processing Toolbox using bwmorph(bw,'thin')
.