Edge Detection - Customizing Masks

I am trying to apply a Roberts-style edge detection to an image, however I do not want to use the Roberts algorithm supplied by the matlab code i.e. NOT: edge(I,'roberts'). The Roberts masks I need to apply to the image are: x=[1 0;0 -1] y=[0 -1;1 0], which is slightly different that MATLAB's built-in edge(I,'roberts') edge detector.
How can I apply custom Roberts, Sobel, and Prewitt edge detectors in MATLAB?

댓글 수: 1

PATRICK STANTON
PATRICK STANTON 2011년 7월 9일
something like this?:
I = imread('Pic7.bmp');
maskx = [1 0;0 -1];
masky = [0 -1;1 0];
X = imfilter(I,maskx);
Y = imfilter(I,masky);
Z = X+Y;

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2011년 7월 9일

1 개 추천

Yes. That will work. Not sure about the Z though - you might want to take Z = sqrt(single(X).^2 + single(Y).^2) instead. Also, you might want to look into conv2(), which I believe is more highly optimized for speed than imfilter. Be sure to use fliplr and flipud on the masks if the orientation is important though since conv2 flips the kernel.

댓글 수: 1

PATRICK STANTON
PATRICK STANTON 2011년 7월 9일
Thank you for the quick reply! This particular formula only required the sum of the absoulte value of the respective x and y gradients, not a square-root of the sum of squares fortunately. Thank you Obi-Wan.

댓글을 달려면 로그인하십시오.

질문:

2011년 7월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by