详解Harris角点检测及代码实现

来源:互联网 发布:js断点调试debugger 编辑:程序博客网 时间:2024/05/22 14:10

转自:http://blog.csdn.net/dandan_397/article/details/42110719


1. 首先,我们不禁要问什么是harris角点?

       对于角点,到目前为止还没有明确的数学定义。但是你可以认为角点就是极值点,即在某方面属性特别突出的点。一般的角点检测都是对有具体定义的、或者是能够具体检测出来的兴趣点的检测。这意味着兴趣点可以是角点,是在某些属性上强度最大或者最小的孤立点、线段的终点,或者是曲线上局部曲率最大的点。

       通俗的来说,在一副图像中,我们可以认为角点是物体轮廓线的连接点(见图1),当拍摄视角变化的时候,这些特征点仍能很好地保持稳定的属性。

                                                 

                                                                 图1  corner

       角点在保留图像图形重要特征的同时,可以有效地减少信息的数据量,使其信息的含量很高,有效地提高了计算的速度,有利于图像的可靠匹配,使得实时处理成为可能。它的各种应用,这里我就不再赘述了。

2. 如何检测出harris角点?

                                 

                                                         图2  角点检测的基本思想

       角点检测最原始的想法就是取某个像素的一个邻域窗口,当这个窗口在各个方向上进行小范围移动时,观察窗口内平均的像素灰度值的变化(即,E(u,v),Window-averaged change of intensity)。从上图可知,我们可以将一幅图像大致分为三个区域(‘flat’,‘edge’,‘corner’),这三个区域变化是不一样的。

                       

      其中,u,v是窗口在水平,竖直方向的偏移,

                     

      这里可以先简单复习一下泰勒级数展开的知识,因为马上就用到啦,


            

这是一维的情况,对于多元函数,也有类似的泰勒公式。

       对I(x+u,y+v)进行二维泰勒级数展开,我们取一阶近似,有

                                    

        图中蓝线圈出的部分我们称之为结构张量(structure tensor),用M表示。

        讲到这里,先明确一点,我们的目的是什么?我们的目的是寻找这样的像素点,它使得我们的u,v无论怎样取值,E(u,v)都是变化比较大的,这个像素点就是我们要找的角点。不难观察,上式近似处理后的E(u,v)是一个二次型,而由下述定理可知,

                            

        令E(u,v)=常数,我们可用一个椭圆来描绘这一函数。

                                                

         椭圆的长短轴是与结构张量M的两个特征值相对应的量。通过判断的情况我们就可以区分出‘flat’,‘edge’,‘corner’这三种区域,因为最直观的印象:

corner:在水平、竖直两个方向上变化均较大的点,即Ix、Iy都较大; 
 edge :仅在水平、或者仅在竖直方向有较大的点,即Ix和Iy只有其一较大 ;
  flat   : 在水平、竖直方向的变化量均较小的点,即Ix、Iy都较小;

       而结构张量M是由Ix,Iy构成,它的特征值正好可以反映Ix,Iy的情况,下面我以一种更容易理解的方式来讲述椭圆的物理意义。

                          

                         

                         

         这样是不是更清楚了呢^_^......,因此我们可以得出结论:

                        

         当然,大牛们并没有止步于此,这样通过判断两个变量的值来判断角点毕竟不是很方便。于是他们想出了一种更好的方法,对,就是定义角点响应函数R(corner response function),

                                            

      针对三种区域,R的取值如何呢?

                        

            至此,我们就可以通过判断R的值来判断某个点是不是角点了。

3. harris角点检测算法步骤

               

        值得注意的是,在实际情况中,用来判断R的阈值依赖于实际图像的尺寸、纹理等因素,由于其不具有直观的物理意义,它的取值很难确定。通常我们采用间接的方法来判断R:通过选择图像中R值最大的前n个像素点作为特征点,再对提取到的特征点进行K*K邻域的非极大抑制处理就可以了。

4. Matlab 代码实现

<a target=_blank id="L1" href="http://blog.csdn.net/dandan_397/article/details/42110719#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a><a target=_blank id="L2" href="http://blog.csdn.net/dandan_397/article/details/42110719#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a><a target=_blank id="L3" href="http://blog.csdn.net/dandan_397/article/details/42110719#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a><a target=_blank id="L4" href="http://blog.csdn.net/dandan_397/article/details/42110719#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a><a target=_blank id="L5" href="http://blog.csdn.net/dandan_397/article/details/42110719#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a><a target=_blank id="L6" href="http://blog.csdn.net/dandan_397/article/details/42110719#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a><a target=_blank id="L7" href="http://blog.csdn.net/dandan_397/article/details/42110719#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a><a target=_blank id="L8" href="http://blog.csdn.net/dandan_397/article/details/42110719#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a><a target=_blank id="L9" href="http://blog.csdn.net/dandan_397/article/details/42110719#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a><a target=_blank id="L10" href="http://blog.csdn.net/dandan_397/article/details/42110719#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a><a target=_blank id="L11" href="http://blog.csdn.net/dandan_397/article/details/42110719#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a><a target=_blank id="L12" href="http://blog.csdn.net/dandan_397/article/details/42110719#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a><a target=_blank id="L13" href="http://blog.csdn.net/dandan_397/article/details/42110719#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a><a target=_blank id="L14" href="http://blog.csdn.net/dandan_397/article/details/42110719#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a><a target=_blank id="L15" href="http://blog.csdn.net/dandan_397/article/details/42110719#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a><a target=_blank id="L16" href="http://blog.csdn.net/dandan_397/article/details/42110719#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a><a target=_blank id="L17" href="http://blog.csdn.net/dandan_397/article/details/42110719#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a><a target=_blank id="L18" href="http://blog.csdn.net/dandan_397/article/details/42110719#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a><a target=_blank id="L19" href="http://blog.csdn.net/dandan_397/article/details/42110719#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a><a target=_blank id="L20" href="http://blog.csdn.net/dandan_397/article/details/42110719#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a><a target=_blank id="L21" href="http://blog.csdn.net/dandan_397/article/details/42110719#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a><a target=_blank id="L22" href="http://blog.csdn.net/dandan_397/article/details/42110719#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a><a target=_blank id="L23" href="http://blog.csdn.net/dandan_397/article/details/42110719#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a><a target=_blank id="L24" href="http://blog.csdn.net/dandan_397/article/details/42110719#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a><a target=_blank id="L25" href="http://blog.csdn.net/dandan_397/article/details/42110719#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;"> 25</a><a target=_blank id="L26" href="http://blog.csdn.net/dandan_397/article/details/42110719#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;"> 26</a><a target=_blank id="L27" href="http://blog.csdn.net/dandan_397/article/details/42110719#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;"> 27</a><a target=_blank id="L28" href="http://blog.csdn.net/dandan_397/article/details/42110719#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;"> 28</a><a target=_blank id="L29" href="http://blog.csdn.net/dandan_397/article/details/42110719#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;"> 29</a><a target=_blank id="L30" href="http://blog.csdn.net/dandan_397/article/details/42110719#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;"> 30</a><a target=_blank id="L31" href="http://blog.csdn.net/dandan_397/article/details/42110719#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;"> 31</a><a target=_blank id="L32" href="http://blog.csdn.net/dandan_397/article/details/42110719#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;"> 32</a><a target=_blank id="L33" href="http://blog.csdn.net/dandan_397/article/details/42110719#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;"> 33</a><a target=_blank id="L34" href="http://blog.csdn.net/dandan_397/article/details/42110719#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;"> 34</a><a target=_blank id="L35" href="http://blog.csdn.net/dandan_397/article/details/42110719#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;"> 35</a><a target=_blank id="L36" href="http://blog.csdn.net/dandan_397/article/details/42110719#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;"> 36</a><a target=_blank id="L37" href="http://blog.csdn.net/dandan_397/article/details/42110719#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;"> 37</a><a target=_blank id="L38" href="http://blog.csdn.net/dandan_397/article/details/42110719#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;"> 38</a><a target=_blank id="L39" href="http://blog.csdn.net/dandan_397/article/details/42110719#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;"> 39</a><a target=_blank id="L40" href="http://blog.csdn.net/dandan_397/article/details/42110719#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;"> 40</a><a target=_blank id="L41" href="http://blog.csdn.net/dandan_397/article/details/42110719#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;"> 41</a><a target=_blank id="L42" href="http://blog.csdn.net/dandan_397/article/details/42110719#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;"> 42</a><a target=_blank id="L43" href="http://blog.csdn.net/dandan_397/article/details/42110719#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;"> 43</a><a target=_blank id="L44" href="http://blog.csdn.net/dandan_397/article/details/42110719#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;"> 44</a><a target=_blank id="L45" href="http://blog.csdn.net/dandan_397/article/details/42110719#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;"> 45</a><a target=_blank id="L46" href="http://blog.csdn.net/dandan_397/article/details/42110719#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;"> 46</a><a target=_blank id="L47" href="http://blog.csdn.net/dandan_397/article/details/42110719#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;"> 47</a><a target=_blank id="L48" href="http://blog.csdn.net/dandan_397/article/details/42110719#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;"> 48</a><a target=_blank id="L49" href="http://blog.csdn.net/dandan_397/article/details/42110719#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;"> 49</a><a target=_blank id="L50" href="http://blog.csdn.net/dandan_397/article/details/42110719#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;"> 50</a><a target=_blank id="L51" href="http://blog.csdn.net/dandan_397/article/details/42110719#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;"> 51</a><a target=_blank id="L52" href="http://blog.csdn.net/dandan_397/article/details/42110719#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;"> 52</a><a target=_blank id="L53" href="http://blog.csdn.net/dandan_397/article/details/42110719#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;"> 53</a><a target=_blank id="L54" href="http://blog.csdn.net/dandan_397/article/details/42110719#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;"> 54</a><a target=_blank id="L55" href="http://blog.csdn.net/dandan_397/article/details/42110719#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;"> 55</a><a target=_blank id="L56" href="http://blog.csdn.net/dandan_397/article/details/42110719#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;"> 56</a><a target=_blank id="L57" href="http://blog.csdn.net/dandan_397/article/details/42110719#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;"> 57</a><a target=_blank id="L58" href="http://blog.csdn.net/dandan_397/article/details/42110719#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;"> 58</a><a target=_blank id="L59" href="http://blog.csdn.net/dandan_397/article/details/42110719#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;"> 59</a><a target=_blank id="L60" href="http://blog.csdn.net/dandan_397/article/details/42110719#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;"> 60</a><a target=_blank id="L61" href="http://blog.csdn.net/dandan_397/article/details/42110719#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;"> 61</a><a target=_blank id="L62" href="http://blog.csdn.net/dandan_397/article/details/42110719#L62" rel="#L62" style="color: rgb(102, 102, 102); text-decoration: none;"> 62</a><a target=_blank id="L63" href="http://blog.csdn.net/dandan_397/article/details/42110719#L63" rel="#L63" style="color: rgb(102, 102, 102); text-decoration: none;"> 63</a><a target=_blank id="L64" href="http://blog.csdn.net/dandan_397/article/details/42110719#L64" rel="#L64" style="color: rgb(102, 102, 102); text-decoration: none;"> 64</a><a target=_blank id="L65" href="http://blog.csdn.net/dandan_397/article/details/42110719#L65" rel="#L65" style="color: rgb(102, 102, 102); text-decoration: none;"> 65</a><a target=_blank id="L66" href="http://blog.csdn.net/dandan_397/article/details/42110719#L66" rel="#L66" style="color: rgb(102, 102, 102); text-decoration: none;"> 66</a><a target=_blank id="L67" href="http://blog.csdn.net/dandan_397/article/details/42110719#L67" rel="#L67" style="color: rgb(102, 102, 102); text-decoration: none;"> 67</a><a target=_blank id="L68" href="http://blog.csdn.net/dandan_397/article/details/42110719#L68" rel="#L68" style="color: rgb(102, 102, 102); text-decoration: none;"> 68</a><a target=_blank id="L69" href="http://blog.csdn.net/dandan_397/article/details/42110719#L69" rel="#L69" style="color: rgb(102, 102, 102); text-decoration: none;"> 69</a><a target=_blank id="L70" href="http://blog.csdn.net/dandan_397/article/details/42110719#L70" rel="#L70" style="color: rgb(102, 102, 102); text-decoration: none;"> 70</a><a target=_blank id="L71" href="http://blog.csdn.net/dandan_397/article/details/42110719#L71" rel="#L71" style="color: rgb(102, 102, 102); text-decoration: none;"> 71</a><a target=_blank id="L72" href="http://blog.csdn.net/dandan_397/article/details/42110719#L72" rel="#L72" style="color: rgb(102, 102, 102); text-decoration: none;"> 72</a><a target=_blank id="L73" href="http://blog.csdn.net/dandan_397/article/details/42110719#L73" rel="#L73" style="color: rgb(102, 102, 102); text-decoration: none;"> 73</a><a target=_blank id="L74" href="http://blog.csdn.net/dandan_397/article/details/42110719#L74" rel="#L74" style="color: rgb(102, 102, 102); text-decoration: none;"> 74</a><a target=_blank id="L75" href="http://blog.csdn.net/dandan_397/article/details/42110719#L75" rel="#L75" style="color: rgb(102, 102, 102); text-decoration: none;"> 75</a><a target=_blank id="L76" href="http://blog.csdn.net/dandan_397/article/details/42110719#L76" rel="#L76" style="color: rgb(102, 102, 102); text-decoration: none;"> 76</a><a target=_blank id="L77" href="http://blog.csdn.net/dandan_397/article/details/42110719#L77" rel="#L77" style="color: rgb(102, 102, 102); text-decoration: none;"> 77</a><a target=_blank id="L78" href="http://blog.csdn.net/dandan_397/article/details/42110719#L78" rel="#L78" style="color: rgb(102, 102, 102); text-decoration: none;"> 78</a><a target=_blank id="L79" href="http://blog.csdn.net/dandan_397/article/details/42110719#L79" rel="#L79" style="color: rgb(102, 102, 102); text-decoration: none;"> 79</a><a target=_blank id="L80" href="http://blog.csdn.net/dandan_397/article/details/42110719#L80" rel="#L80" style="color: rgb(102, 102, 102); text-decoration: none;"> 80</a><a target=_blank id="L81" href="http://blog.csdn.net/dandan_397/article/details/42110719#L81" rel="#L81" style="color: rgb(102, 102, 102); text-decoration: none;"> 81</a><a target=_blank id="L82" href="http://blog.csdn.net/dandan_397/article/details/42110719#L82" rel="#L82" style="color: rgb(102, 102, 102); text-decoration: none;"> 82</a><a target=_blank id="L83" href="http://blog.csdn.net/dandan_397/article/details/42110719#L83" rel="#L83" style="color: rgb(102, 102, 102); text-decoration: none;"> 83</a><a target=_blank id="L84" href="http://blog.csdn.net/dandan_397/article/details/42110719#L84" rel="#L84" style="color: rgb(102, 102, 102); text-decoration: none;"> 84</a><a target=_blank id="L85" href="http://blog.csdn.net/dandan_397/article/details/42110719#L85" rel="#L85" style="color: rgb(102, 102, 102); text-decoration: none;"> 85</a><a target=_blank id="L86" href="http://blog.csdn.net/dandan_397/article/details/42110719#L86" rel="#L86" style="color: rgb(102, 102, 102); text-decoration: none;"> 86</a><a target=_blank id="L87" href="http://blog.csdn.net/dandan_397/article/details/42110719#L87" rel="#L87" style="color: rgb(102, 102, 102); text-decoration: none;"> 87</a><a target=_blank id="L88" href="http://blog.csdn.net/dandan_397/article/details/42110719#L88" rel="#L88" style="color: rgb(102, 102, 102); text-decoration: none;"> 88</a><a target=_blank id="L89" href="http://blog.csdn.net/dandan_397/article/details/42110719#L89" rel="#L89" style="color: rgb(102, 102, 102); text-decoration: none;"> 89</a><a target=_blank id="L90" href="http://blog.csdn.net/dandan_397/article/details/42110719#L90" rel="#L90" style="color: rgb(102, 102, 102); text-decoration: none;"> 90</a><a target=_blank id="L91" href="http://blog.csdn.net/dandan_397/article/details/42110719#L91" rel="#L91" style="color: rgb(102, 102, 102); text-decoration: none;"> 91</a><a target=_blank id="L92" href="http://blog.csdn.net/dandan_397/article/details/42110719#L92" rel="#L92" style="color: rgb(102, 102, 102); text-decoration: none;"> 92</a><a target=_blank id="L93" href="http://blog.csdn.net/dandan_397/article/details/42110719#L93" rel="#L93" style="color: rgb(102, 102, 102); text-decoration: none;"> 93</a><a target=_blank id="L94" href="http://blog.csdn.net/dandan_397/article/details/42110719#L94" rel="#L94" style="color: rgb(102, 102, 102); text-decoration: none;"> 94</a>
clear;
% ori_im =double(imread('lena.jpg')); % 读取图像
ori_im = imread('pig.jpg');
% ori_im = imread('Baboon.bmp');
% figure,
% imshow(ori_im),
% title('the original image')
ori_gray = rgb2gray(ori_im);
% fx = [5 0 -5;8 0 -8;5 0 -5]; % 高斯函数一阶微分,x方向(用于改进的Harris角点提取算法)
fx = [-2 -1 0 1 2]; % x方向梯度算子(用于Harris角点提取算法)
Ix = filter2(fx,ori_gray); % x方向滤波
% fy = [5 8 5;0 0 0;-5 -8 -5]; % 高斯函数一阶微分,y方向(用于改进的Harris角点提取算法)
fy = [-2;-1;0;1;2]; % y方向梯度算子(用于Harris角点提取算法)
Iy = filter2(fy,ori_gray); % y方向滤波
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
%% 考虑到图像一般情况下的噪声影响,采用高斯滤波去除噪声点
h= fspecial('gaussian',[7 7],2); % 产生7*7的高斯窗函数,sigma=2
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(ori_gray,1);
width = size(ori_gray,2);
result = zeros(height,width); % 纪录角点位置,角点处值为1
%% 计算角点的响应函数R(即用一个值来衡量这个点是否是角点),并标记角点(R(i,j)>0.01*Rmax,且R(i,j)为3x3邻域局部最大值)
k=1;
lambda=zeros(height*width,2);
R = zeros(height,width);
for i = 1:height
for j = 1:width
M = [Ix2(i,j) Ixy(i,j);Ixy(i,j) Iy2(i,j)]; % auto correlation matrix
K = det(M); %求行列式
H = trace(M); %求迹
% R(i,j) = det(M)-0.06*(trace(M))^2;
R(i,j) = K-0.06*H^2;
lambda(k,:)=[K H];
k=k+1;
end;
end;
figure,
plot(lambda(:,1),lambda(:,2),'.');
ylabel('trace');xlabel('det');
%%
cnt = 0;
for i = 2:height-1
for j = 2:width-1
% 进行非极大抑制,窗口大小3*3
if R(i,j) > R(i-1,j-1) && R(i,j) > R(i-1,j) && R(i,j) > R(i-1,j+1) && R(i,j) > R(i,j-1) && R(i,j) > R(i,j+1) && R(i,j) > R(i+1,j-1) && R(i,j) > R(i+1,j) && R(i,j) > R(i+1,j+1)
result(i,j) = 1;
cnt = cnt+1;
end;
end;
end;
Rsort=zeros(cnt,1);
[posr, posc] = find(result == 1);
for i=1:cnt
Rsort(i)=R(posr(i),posc(i));
end;
[Rsort,ix]=sort(Rsort,1);
Rsort=flipud(Rsort);
ix=flipud(ix);
ps=120;
posr2=zeros(ps,1);
posc2=zeros(ps,1);
pos=zeros(ps,1);
for i=1:ps
posr2(i)=posr(ix(i));
posc2(i)=posc(ix(i));
pos(i)= (posr2(i)-1)*width+posc2(i);
end;
hold on,
plot(lambda(pos,1),lambda(pos,2),'r*');
legend('flat & edges','corners')
figure,
imshow(ori_im);
hold on;
plot(posc2,posr2,'g.');
 来自CODE的代码片
harris.m

实验结果:

                                       

      再附一张中间结果图,det(M) 与trace(M)的分布图,便于大家更好地理解R,

                                      

      我在上面做了一些标记,

                                    


            欢迎大家一起学习交流!


  C.Harris, M.Stephens. “A Combined Corner and Edge Detector”. 1988


0 0
原创粉丝点击