Implementation of the Roberts operator in edge function

7 views (last 30 days)
Hello, using the open edge command, and looking for the area in which Roberts would be implemented I have a series of questions to see if anyone knows why it is done this way.
elseif strcmp(method, 'roberts')
x_mask = [1 0; 0 -1]/2; % Roberts approximation to diagonal derivative
y_mask = [0 1;-1 0]/2;
scale = 6;
offset = [-1 1 1 -1];
% compute the gradient in x and y direction
bx = imfilter(a,x_mask,'replicate');
by = imfilter(a,y_mask,'replicate');
% compute the magnitude
b = kx*bx.*bx + ky*by.*by;
The first question is because it uses as filters in x and in y those that appear in all the manuals, as for example in [1] but divided by 2.
The second is why it uses the imfilter function with replicate instead of using conv
And finally, the third one is why this method computes the magnitude of the gradient using this expression insted of using this one:
Thank you for all.
For me, the correct edge function should be something like:
function [BW,G45,G135] = Roberts(I,T)
I = im2single(I);
% Roberts approximation to diagonal derivative
x_mask = [1 0; 0 -1];
y_mask = [0 1;-1 0];
% compute the gradient in x and y direction
G45 = imfilter(I,x_mask,'conv');
G135 = imfilter(I,y_mask,'conv');
% compute the magnitude
M = sqrt(G45.^2+G135.^2);
% Create BW image
BW = false(size(I));
BW(M(:)>T) = 1;

Answers (1)

Image Analyst
Image Analyst on 31 May 2020
What is the "open edge command"?
The first question is not even a question. Dividing by 2 merely changes the range from -255 to +255 to -128 to +127.
For the second question, you can use conv2() or imfilter(). I believe imfilter() does not flip the kernel like conv2() does.
For the third question, it was the programmers choice how to pick the angles of the edge. If there are lots of horizontal and vertical angles, you could get more signal with the standard kernel rather than the diagonal ones. If there are more angles at 45 and 135 then you'd get a stronger signal using the angled kernel. It's not like one if always better and one is always worse or wrong. You're free to do whatever gives you the best signal in your particular case.
  1 Comment
Alejandro Fernández
Alejandro Fernández on 31 May 2020
Edited: Alejandro Fernández on 31 May 2020
open edge
edit edge
open edge or edit edge are the commands you have to type in order to see the code inside a function, in this case the edge function.
  1. But the range should not be from 0 to +255?
  2. Ok, thank you.
  3. THe main problem with this one is that I dont understand what Kx and Ky are.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!