Susan Corner Detector implementation

橙三吉。 提交于 2019-12-10 12:27:23

问题


I have not understood the code and the way function is handled..

can you elaborate the function declaration

fun = @(img) susanFun(img);
map = nlfilter(img,maskSz,fun);

Also in susan corner detector we have only 2 threshold values.. "t and g".. but here we have "thGeo,thGeo1,thGeo2,thT,thT1"

I am not able to understand the method employed here:

function [ map r c ] = susanCorner( img )
%SUSAN Corner detection using SUSAN method.
%   [R C] = SUSAN(IMG)  Rows and columns of corner points are returned.


maskSz = [7 7];
fun = @(img) susanFun(img);
map = nlfilter(img,maskSz,fun);
[r c] = find(map);

end

function res = susanFun(img)
% SUSANFUN  Determine if the center of the image patch IMG
%   is corner(res = 1) or not(res = 0)


mask = [...
    0 0 1 1 1 0 0
    0 1 1 1 1 1 0
    1 1 1 1 1 1 1
    1 1 1 1 1 1 1
    1 1 1 1 1 1 1
    0 1 1 1 1 1 0
    0 0 1 1 1 0 0];

% uses 2 thresholds to distinguish corners from edges
thGeo = (nnz(mask)-1)*.2;
thGeo1 = (nnz(mask)-1)*.4;
thGeo2 = (nnz(mask)-1)*.4;
thT = .07;
thT1 = .04;

sz = size(img,1);
usan = ones(sz)*img(round(sz/2),round(sz/2));

similar = (abs(usan-img)<thT);
similar = similar.*mask;
res = sum(similar(:));
if res < thGeo
    dark = nnz((img-usan<-thT1).*mask);
    bright = nnz((img-usan>thT1).*mask);
    res = min(dark,bright)<thGeo1 && max(dark,bright)>thGeo2;

else
    res = 0;
end

end

回答1:


fun = @(img) susanFun(img);
map = nlfilter(img,maskSz,fun);

means

  • fun is a handle (or pointer) to a function.
  • @(img) says fun takes an argument called img.
  • susanFun(img) is the body of fun

nlfilter is passed the function handle fun and can call it. In fact, it will apply fun with the parameter img as each 7x7 sliding block of the image img. Note that the name img is overloaded here: it is name name of a variable holding an image, and it is the name of the parameter of fun.

See function_handle (@)



来源:https://stackoverflow.com/questions/19753541/susan-corner-detector-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!