热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

分析OpenSurf(2)

①积分图像的实现首先在Integral.cpp里面找到Integral(),如下:IplImage*Integral(IplImage*source)

①积分图像的实现

 首先在Integral.cpp里面找到Integral(),如下:

IplImage *Integral(IplImage *source)
{//转换成单通道图像 convert the image to single channel 32fIplImage *img = getGray(source);IplImage *int_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_32F, 1);//给变量赋值 set up variables for data accessint height = img->height;int width = img->width;int step = img->widthStep/sizeof(float);float *data = (float *) img->imageData; float *i_data = (float *) int_img->imageData; //仅限第一行 first row onlyfloat rs = 0.0f;for(int j=0; j}

1.  首先将原输入转化为灰度图像,并创建一个大小等于灰度图像gray-image的图像数组--积分图像int_img。

2.  获取图像的信息,比如大小(高height和宽width)以及gray-image和积分图像int_img的数据首地址data && i_data。(注意此时数据类型为float)

3.  首先计算第一行像素的积分值,相当于一维数据的累加。其他数据通过迭代计算获取,i_data[i*step+j] = rs + i_data[(i-1)*step+j],若当前点为(i,j),其中rs就为第 i 行第 j 列之前(包括第 i 行第 j 列)所有像素值和。 如下所示:

                                        

 [其中黑色为当前点i_data[i*step+j],绿色为当前点同一列上一行的点i_data[(i-1)*step+j],而rs=横放着的和黑色点同行的那块矩形框对应的区域像素值之和]

4.  释放灰度图像,并返回积分图像。

 

integral.h中的相关函数:  BoxIntegral().

inline float BoxIntegral(IplImage *img, int row, int col, int rows, int cols)

其中,几个参数意思分别为源图像,row,col为A点的坐标值,rows和cols分别为高和宽。

利用上面的积分图像计算   A      B   这样的box区域里面所有像素点的灰度值之和。S=int_img(D)+int_img(A)-int_img(B)-int_img(C).

                                         C      D 



②Hessian矩阵特征的计算

FastHessian,计算hessian矩阵的类,它的定义在fasthessian.h里,实现在fasthessian.cpp里。

class FastHessian {public://! Constructor without imageFastHessian(std::vector &ipts, const int octaves = OCTAVES, const int intervals = INTERVALS, const int init_sample = INIT_SAMPLE, const float thres = THRES);//! Constructor with imageFastHessian(IplImage *img, std::vector &ipts, const int octaves = OCTAVES, const int intervals = INTERVALS, const int init_sample = INIT_SAMPLE, const float thres = THRES);//! Destructor~FastHessian();//! Save the parametersvoid saveParameters(const int octaves, const int intervals,const int init_sample, const float thres);//!设置或重设源积分图像 Set or re-set the integral image sourcevoid setIntImage(IplImage *img);//!寻找图像特征并写入特征向量 Find the image features and write into vector of featuresvoid getIpoints();private://---------------- Private Functions -----------------////! Build map of DoH(Determinant of Hessian) responsesvoid buildResponseMap();//! Calculate DoH responses for supplied layervoid buildResponseLayer(ResponseLayer *r);//! 3x3x3 Extrema testint isExtremum(int r, int c, ResponseLayer *t, ResponseLayer *m, ResponseLayer *b); //! 插值函数Interpolation functions - adapted from Lowe's SIFT implementationvoid interpolateExtremum(int r, int c, ResponseLayer *t, ResponseLayer *m, ResponseLayer *b);void interpolateStep(int r, int c, ResponseLayer *t, ResponseLayer *m, ResponseLayer *b,double* xi, double* xr, double* xc );CvMat* deriv3D(int r, int c, ResponseLayer *t, ResponseLayer *m, ResponseLayer *b);CvMat* hessian3D(int r, int c, ResponseLayer *t, ResponseLayer *m, ResponseLayer *b);//---------------- Private Variables -----------------////! Pointer to the integral Image, and its attributes IplImage *img;int i_width, i_height;//! Reference to vector of features passed from outside std::vector &ipts;//!海森矩阵行列式的响应栈 Response stack of determinant of hessian valuesstd::vector responseMap;//! 高斯金字塔的组数int octaves;//! 每组的层数int intervals;//! 特征点检测的初始抽样步骤 Initial sampling step for Ipoint detectionint init_sample;//! Threshold value for blob resonsesfloat thresh;
};

在public里面定义了两种构造函数分别对应有无源图像这一项参数,紧接着还定义了析构函数~FastHessian等函数。下面在fasthessian.cpp对这些函数的实现一一解释:

两个构造函数都是调用了saveParameters(octaves, intervals, init_sample, thresh)设置构造金字塔的参数,而带图像的构造函数另外多加了一句setIntImage(img)用来设置当前图像。

//! Save the parameters
void FastHessian::saveParameters(const int octaves, const int intervals, const int init_sample, const float thresh)
{// Initialise variables with bounds-checked valuesthis->octaves &#61; (octaves > 0 && octaves <&#61; 4 ? octaves : OCTAVES);this->intervals &#61; (intervals > 0 && intervals <&#61; 4 ? intervals : INTERVALS);this->init_sample &#61; (init_sample > 0 && init_sample <&#61; 6 ? init_sample : INIT_SAMPLE);this->thresh &#61; (thresh >&#61; 0 ? thresh : THRES);
}//! Set or re-set the integral image source
void FastHessian::setIntImage(IplImage *img)
{// Change the source imagethis->img &#61; img;i_height &#61; img->height;i_width &#61; img->width;
}

由于在h头文件中已设置

static const int OCTAVES &#61; 5;//组数
static const int INTERVALS &#61; 4;//每组层数
static const float THRES &#61; 0.0004f;//阈值
static const int INIT_SAMPLE &#61; 2;//初始采样因子

所以 saveParameters的作用就是调整参数&#xff0c;以防过大或过小。

FastHessian::getIpoints()提取兴趣点&#xff1a;

//! Find the image features and write into vector of features
void FastHessian::getIpoints()
{// filter index mapstatic const int filter_map [OCTAVES][INTERVALS] &#61; {{0,1,2,3}, {1,3,4,5}, {3,5,6,7}, {5,7,8,9}, {7,9,10,11}};// Clear the vector of exisiting iptsipts.clear();// Build the response mapbuildResponseMap();// Get the response layers...
...
}

首先初始化filter_map&#xff0c;清空标记特征点的ipts结构体。

 创建高斯平滑层函数参数ResponseMap()&#xff0c;大小与论文所给完全一致&#xff0c;

         // Oct1: 9, 15, 21, 27
         // Oct2: 15, 27, 39, 51
         // Oct3: 27, 51, 75, 99
         // Oct4: 51, 99, 147,195
         // Oct5: 99, 195,291,387

这些都是每组模板的大小&#xff0c;每组间隔递增&#xff0c;6,12,24,48,96 。ResponseMap这个结构体向量包含4个参数ResponseLayer(int width, int height, int step, int filter)定义在responsemap.h里面&#xff0c;其中width和height等于实际图像大小除以step(step初始值为2)&#xff0c;而filter则是滤波器半径。

 

然后使用buildResponseLayer(responseMap[i])对图像处理后将数据存放在responses和laplacian两个数组里面。

void FastHessian::buildResponseLayer(ResponseLayer *rl)
{float *responses &#61; rl->responses; // response storageunsigned char *laplacian &#61; rl->laplacian; // laplacian sign storageint step &#61; rl->step; // step size for this filter 滤波器尺度因子int b &#61; (rl->filter - 1) / 2; // border for this filter 滤波器边界int l &#61; rl->filter / 3; // lobe for this filter (filter size / 3)int w &#61; rl->filter; // filter size 滤波器大小float inverse_area &#61; 1.f/(w*w); // normalisation factor 标准化因子float Dxx, Dyy, Dxy;for(int r, c, ar &#61; 0, index &#61; 0; ar height; &#43;&#43;ar) {for(int ac &#61; 0; ac width; &#43;&#43;ac, index&#43;&#43;) {// get the image coordinatesr &#61; ar * step;c &#61; ac * step; // Compute response componentsDxx &#61; BoxIntegral(img, r - l &#43; 1, c - b, 2*l - 1, w)- BoxIntegral(img, r - l &#43; 1, c - l / 2, 2*l - 1, l)*3;Dyy &#61; BoxIntegral(img, r - b, c - l &#43; 1, w, 2*l - 1)- BoxIntegral(img, r - l / 2, c - l &#43; 1, l, 2*l - 1)*3;Dxy &#61; &#43; BoxIntegral(img, r - l, c &#43; 1, l, l)&#43; BoxIntegral(img, r &#43; 1, c - l, l, l)- BoxIntegral(img, r - l, c - l, l, l)- BoxIntegral(img, r &#43; 1, c &#43; 1, l, l);// Normalise the filter responses with respect to their sizeDxx *&#61; inverse_area;Dyy *&#61; inverse_area;Dxy *&#61; inverse_area;// Get the determinant of hessian response & laplacian signresponses[index] &#61; (Dxx * Dyy - 0.81f * Dxy * Dxy);laplacian[index] &#61; (Dxx &#43; Dyy >&#61; 0 ? 1 : 0);#ifdef RL_DEBUG// create list of the image coords for each responserl->coords.push_back(std::make_pair(r,c));
#endif}}
}

其中计算Dxy和Dyy的示意图如下&#xff0c;其他的Dxx(Dyy的转置)读者自己参考。【此时w&#61;9,l&#61;9/3&#61;3,对应于右图的总计算区域高度和宽度2*l-1】

 

         

  圆点为当前点&#xff0c;将红色方形区域1内的积分值减去绿色方形2区域内的积分值&#61;Dxy*w2                 

 绿色方形区域2内的积分值减去2*红色色方形区域1内的积分值&#61;Dyy*w2 (&#61;&#61;用一整块区域-3*红色区域&#xff09;

 最后将计算后的结果存放到ResponseLayer里面的response和laplacian一维数组里&#xff0c;数组的大小即为ResponseLayer->width * ResponseLayer->width。

 

这样就计算出了每一层的所有像素点的det(Happrox)&#61;Dxx*Dyy-(0.9*Dxy)2,下面开始判断当前点是否是极值点。






















推荐阅读
  • ImmutableX Poised to Pioneer Web3 Gaming Revolution
    ImmutableX is set to spearhead the evolution of Web3 gaming, with its innovative technologies and strategic partnerships driving significant advancements in the industry. ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 数据管理权威指南:《DAMA-DMBOK2 数据管理知识体系》
    本书提供了全面的数据管理职能、术语和最佳实践方法的标准行业解释,构建了数据管理的总体框架,为数据管理的发展奠定了坚实的理论基础。适合各类数据管理专业人士和相关领域的从业人员。 ... [详细]
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • c# – UWP:BrightnessOverride StartOverride逻辑 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 本文详细介绍了Java中org.w3c.dom.Text类的splitText()方法,通过多个代码示例展示了其实际应用。该方法用于将文本节点在指定位置拆分为两个节点,并保持在文档树中。 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • 本文介绍如何使用阿里云的fastjson库解析包含时间戳、IP地址和参数等信息的JSON格式文本,并进行数据处理和保存。 ... [详细]
  • 题目Link题目学习link1题目学习link2题目学习link3%%%受益匪浅!-----&# ... [详细]
author-avatar
哭着说再见0
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有