关于DoG角点检测matlab实现

今天研究了下DoG角点检测算法实现,思路很简单,实现也很容易,不过一开始就是出不来预期的结果

后来参考了DoG (Difference of Gaussian)角点检测
的blog,参考源码,发现了自己代码中的两个问题,就发上来,做个提醒吧
1.没有对原始的输入图片double处理,这个问题以前学图像处理的时候遇到过,当时明白了,现在又忘了,就记在这里吧。

2.没有判断level,这个问题直接导致我们出来的结果 全部都是角点信息了, 参考发现,这边应该有个判断,用来过滤掉一部分候选点

下面给出参考图片,参考图片出处利用Harris检测子进行角点特征检测(含matlab源码)

关于DoG角点检测matlab实现_第1张图片

将这个效果与harris检测结果比较,感觉效果不是很好,可能是我们的参数设置问题吧233333333

% -----------------【自己实现 DOG 检测焦点的算法】------------------
% @ date : 20150516
% @ author : zhyh2010
% @ refer : http://blog.csdn.net/abcjennifer/article/details/7639488
% -------------------------------【end】--------------------------

function main
    clc
    close all
    clear all

    myDogDetector_1;
end

function myDogDetector_1
    src_old = imread('1.jpg');
    src = rgb2gray(src_old);
    src = double(src);  % missing double handle

% h1 = fspecial('gaussian', 5, 0.5);
% h2 = fspecial('gaussian', 5, 1);
% h3 = fspecial('gaussian', 5, 2);
% h4 = fspecial('gaussian', 5, 3);
    h1 = fspecial('gaussian', 5, 0.3);
    h2 = fspecial('gaussian', 5, 0.4);
    h3 = fspecial('gaussian', 5, 0.5);
    h4 = fspecial('gaussian', 5, 0.6);

    src1 = imfilter(src, h1);
    src2 = imfilter(src, h2);
    src3 = imfilter(src, h3);
    src4 = imfilter(src, h4);

    % ----------------------------【DoG detector】----------------------
    src12 = src1 - src2;
    src23 = src3 - src2;
    src34 = src4 - src3;

    src_DoG(:,:,1) = src12;
    src_DoG(:,:,2) = src23;
    src_DoG(:,:,3) = src34;

    figure,imshow(src12);
    figure,imshow(src23);
    figure,imshow(src34);

    result = zeros(size(src_DoG, 1), size(src_DoG, 2));

    % -------------- 【查找DoG 焦点】-------------------
    level = 5;

    around = zeros(1,9);
    for i = 2:size(src_DoG, 1)-1
        for j = 2:size(src_DoG, 2)-1

            % -------------- 【查找周围26 个像素值 并放入数组中】-------------------
            around_id = 1;
            for ii = i-1:i+1
                for jj = j-1:j+1
                    for layer = 1:3
                        if (ii == i) && (jj == j) && layer == 2
                            continue;
                        end

                        around(around_id) = src_DoG(ii, jj, layer);
                        around_id = around_id + 1;
                    end                    
                end
            end

            around_max = max(around);
            around_min = min(around);

            if (around_max < src_DoG(i, j, 2)) ...
                    || (around_min > src_DoG(i, j, 2))
                if around_max > level || around_min < -level   % missing level judge
                    result(i, j) = 2;
                end
            end

        end
    end

    % -----------------------【绘图】-------------------------
    [posy, posx] = find(result == 1);
    figure, imshow(src_old)
    hold on
    plot(posx, posy, '.');

    saveas(gcf, 'res2', 'bmp')

end

参考资料:
DoG (Difference of Gaussian)角点检测

你可能感兴趣的:(matlab,Dog,角点检测)