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!