DOG检测

共享一个代码算了,太忙鸟,有时间在补充。

function [] = dog_learn()

img = imread('/Users/img/lena.png');
img = rgb2gray(img);
gausFilter = fspecial('gaussian', [3,3], 4); %调节这个4这个值,发现求出来的点几乎没有变化
img = imfilter(img, gausFilter, 'replicate');

sigma = 1.6;
k = 2^(1.0/3);
diff_1 = dog_of_img(img, sigma, k*sigma);

diff_2 = dog_of_img(img, k*sigma, k*k*sigma);

diff_3 = dog_of_img(img, k^2*sigma, k^3*sigma);

[point_r, point_c] = max_point(diff_1, diff_2, diff_3);
plot(point_c, -point_r, '.');
end

function [point_r, point_c] = max_point(diff1, diff2, diff3)
[rows, cols] = size(diff1);
point_r = [];
point_c = [];
for i = 2 : rows-1
    for j = 2 : cols-1
        point1 = diff1(i-1:i+1, j-1:j+1);
        point3 = diff3(i-1:i+1, j-1:j+1);
        point2 = diff2(i-1:i+1, j-1:j+1);
        max_point1 = max(max(point1));
        max_point3 = max(max(point3));
        max_point2 = max(max(point2));
        if point2(1,1) > 0.8*max_point1 && point2(1,1) > 0.8*max_point3 && point2(1,1) > 0.9*max_point2
            point_r(end+1) = i;
            point_c(end+1) = j;
        end
    end
end
    
end

function diff_ = dog_of_img(grayImg1,sigma1,sigma2, size)
gausFilter1 = fspecial('gaussian', 2*ceil(3*sigma1)+1, sigma1);
gausFilter2 = fspecial('gaussian', 2*ceil(3*sigma2)+1, sigma2);

blur1 = imfilter(grayImg1, gausFilter1, 'replicate');

blur2 = imfilter(grayImg1, gausFilter2, 'replicate');

diff_ = blur2 - blur1;

end
原文地址:https://www.cnblogs.com/Key-Ky/p/5909139.html