I wrote this code for detecting the edge of the image but the result is different that the built in function result. what is the problem ?
1 回表示 (過去 30 日間)
古いコメントを表示
%Read the original RGB image.
hand = imread('images.jpeg');
figure,imshow(hand);
title('original image')
%extract the green channel
g=hand(:,:,2);
figure,imshow(g);
%Prewitt filter
px=[-1 0 1; -1 0 1; -1 0 1];
cx=filter2(px,g);
figure,imshow(cx/255)
title('horizontal');
py=px';
cy=filter2(py,g);
figure,imshow(cy/255);
title('vertical');
edd=sqrt(cx.^2+cy.^2);
figure,imshow(edd/255);
title('Prewitt filter')
2 件のコメント
Image Analyst
2018 年 12 月 14 日
What built-in function are you using: edge(), or imgradient(), or imgradientxy()?
回答 (1 件)
DGM
2024 年 10 月 9 日
IPT edge() uses multiple different methods for finding edges, then it binarizes and skeletonizes the results. Since we still don't know how edge() was used, here's an attempt to demonstrate a similar result using basic filters.
% a grayscale image
inpict = imread('cameraman.tif');
inpict = im2double(inpict); % put it in unit-scale to begin with
% the reference edgemap
% who knows what threshold or other parameters were used
E = edge(inpict,'prewitt'); % just use defaults
% approximate the binary edgemap using basic tools
% calculate gradient magnitude from derivative estimates
fkx = [-1 0 1; -1 0 1; -1 0 1]; % prewitt
cx = imfilter(inpict,fkx,'replicate');
cy = imfilter(inpict,fkx.','replicate');
Gmag = hypot(cx,cy);
% binarize and skeletonize
Ep = imbinarize(mat2gray(Gmag));
Ep = bwskel(Ep);
% compare
imshow([E Ep])
That's hard to see on the forum, but maybe this is clearer.
imshow(double(cat(3,E,Ep,Ep)))
It's not exact, but for a guess it's close. Edge() does the prewitt/sobel methods in MEX, so it's anybody's guess how the binarization and thinning is performed.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!