Gabor内核参考wiki

使用实数Real的公式计算核函数代码:

Mat getGaborFilter(float lambda, float theta,
float sigma2,float gamma,
float psi = 0.0f){
if(abs(lambda-0.0f)<1e-6){
lambda = 1.0f;
}
float sigma_x = sigma2;
float sigma_y = sigma2/(gamma*gamma);
int nstds = 3;
float sqrt_sigma_x = sqrt(sigma_x);
float sqrt_sigma_y = sqrt(sigma_y);
int xmax = max(abs(nstds*sqrt_sigma_x*cos(theta)),abs(nstds*sqrt_sigma_y*sin(theta)));
int ymax = max(abs(nstds*sqrt_sigma_x*sin(theta)),abs(nstds*sqrt_sigma_y*cos(theta)));
int half_filter_size = xmax>ymax ? xmax:ymax;
int filter_size = 2*half_filter_size+1;
Mat gaber = Mat::zeros(filter_size,filter_size,CV_32F);
for(int i=0;i<filter_size;i++){
float* f = gaber.ptr<float>(i);
for(int j=0;j<filter_size;j++){
int x = j-half_filter_size;
int y = i-half_filter_size;
float x_theta=x*cos(theta)+y*sin(theta);
float y_theta=-x*sin(theta)+y*cos(theta);
f[x] = exp(-.5*(x_theta*x_theta/sigma_x+y_theta*y_theta/sigma_y));
f[x] = f[x]*cos(2*PI*x_theta/lambda+psi);
};
}
return gaber;
}

使用得到的Gabor核对一副图像进行卷积的函数:

Mat gaborFilter(Mat& img, Mat& filter){
int half_filter_size = (max(filter.rows,filter.cols)-1)/2;
Mat filtered_img(img.rows,img.cols,CV_32F);
for(int i=0;i<img.rows;i++){
uchar* img_p = img.ptr<uchar>(i);
float* img_f = filtered_img.ptr<float>(i);
for(int j=0;j<img.cols;j++){
float filter_value = 0.0f;
for(int fi=0;fi<filter.rows;fi++){
float* f = filter.ptr<float>(fi);
int img_i = i+fi-half_filter_size;
img_i = img_i < 0 ? 0 : img_i;
img_i = img_i >= img.rows ? (img.rows-1) : img_i;
uchar* p = img.ptr<uchar>(img_i);
for(int fj=0;fj<filter.cols;fj++){
int img_j = j+fj-half_filter_size;
img_j = img_j < 0 ? 0 : img_j;
img_j = (img_j >= img.cols) ? (img.cols-1) : img_j;
float tmp = (float)p[img_j]*f[fj];
filter_value += tmp;
}
}
img_f[j] = filter_value;
}
}
return filtered_img;
}

对一幅图使用例如以下核卷积:

Mat gaber = getGaborFilter(0.3,0,4,2);

效果例如以下:

Gabor算子卷积之后得到非常多负值(不知道有没有问题)。后面的图是归一化之后显示出来的。

Mat normalizeFilterShow(Mat gaber){
Mat gaber_show = Mat::zeros(gaber.rows,gaber.cols,CV_8UC1);
float gaber_max = FLT_MIN;
float gaber_min = FLT_MAX;
for(int i=0;i<gaber.rows;i++){
float* f = gaber.ptr<float>(i);
for(int j=0;j<gaber.cols;j++){
if(f[j]>gaber_max){
gaber_max = f[j];
}
if(f[j]<gaber_min){
gaber_min = f[j];
}
}
}
float gaber_max_min = gaber_max-gaber_min;
for(int i=0;i<gaber_show.rows;i++){
uchar* p = gaber_show.ptr<uchar>(i);
float* f = gaber.ptr<float>(i);
for(int j=0;j<gaber_show.cols;j++){
if(gaber_max_min!=0.0f){
float tmp = (f[j]-gaber_min)*255.0f/gaber_max_min;
p[j] = (uchar)tmp;
}
else{
p[j] = 255;
}
}
}
return gaber_show;
}

(转载请注明作者和出处:http://blog.csdn.net/xiaowei_cqu 未经同意不用于商业用途)

版权声明:本文博客原创文章。博客,未经同意,不得转载。

【图像处理】Gabor过滤器的更多相关文章

  1. Deep Neural Networks for Object Detection(翻译)

    0 - Abstract 深度神经网络(DNNs)最近在图像分类任务上表现出了突出的性能.在这篇文章中,我们进一步深入探究使用DNNs进行目标检测的问题,这个问题不仅需要对物体进行分类,并且还需要对各 ...

  2. Topographic ICA as a Model of Natural Image Statistics(作为自然图像统计模型的拓扑独立成分分析)

    其实topographic independent component analysis 早在1999年由ICA的发明人等人就提出了,所以不算是个新技术,ICA是在1982年首先在一个神经生理学的背景 ...

  3. PReLU——Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification

    1. 摘要 在 \(ReLU\) 的基础上作者提出了 \(PReLU\),在几乎没有增加额外参数的前提下既可以提升模型的拟合能力,又能减小过拟合风险. 针对 \(ReLU/PReLU\) 的矫正非线性 ...

  4. 图像处理之滤波---gabor

    http://blog.csdn.net/xiaowei_cqu/article/details/24745945 小魏北大

  5. 共有31款PHP 图形/图像处理开源软件(转)

    详情点击:http://www.oschina.net/project/lang/22/php?tag=141&os=0&sort=view PHP 图像处理库 Grafika Gra ...

  6. paper 119:[转]图像处理中不适定问题-图像建模与反问题处理

    图像处理中不适定问题 作者:肖亮博士 发布时间:09-10-25 图像处理中不适定问题(ill posed problem)或称为反问题(inverse Problem)的研究从20世纪末成为国际上的 ...

  7. opencv6.1-imgproc图像处理模块之平滑与形态学操作

    这个部分是<opencv-tutorials.pdf>的部分,这部分也是几大部分中例子最多的,其实这个教程的例子都很不错,不过有些看得出来还是c接口的例子,说明例子有些年头了,其实在&qu ...

  8. opencv6.2-imgproc图像处理模块之图像尺寸上的操作及阈值

    接opencv6.1-imgproc图像处理模块之平滑和形态学操作,顺带说一句在opencv中的in-place操作就是比如函数的输入图像和输出图像两个指针是相同的,那么就是in-place操作了.比 ...

  9. opencv6.3-imgproc图像处理模块之边缘检测

    接opencv6.2-improc图像处理模块之图像尺寸上的操作 本文大部分都是来自于转http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutori ...

随机推荐

  1. Xamarin.Android开发实践(二)

    原文:Xamarin.Android开发实践(二) 一.准备 开始学习本教程前必须先完成该教程http://www.cnblogs.com/yaozhenfa/p/xamarin_android_qu ...

  2. literal控件的例子

    Literal的Mode属性,举例说明 这个属性的枚举值:PassThrough  Encode  Transform <%@ Page Language="C#" Auto ...

  3. 开发记录_自学Python写爬虫程序爬取csdn个人博客信息

    每天刷开csdn的博客,看到一整个页面,其实对我而言,我只想看看访问量有没有上涨而已... 于是萌生了一个想法: 想写一个爬虫程序把csdn博客上边的访问量和评论数都爬下来. 打算通过网络各种搜集资料 ...

  4. HH的军训(容斥)

    1248: HH的军训 时间限制: 1 Sec  内存限制: 128 MB 提交: 95  解决: 11 [提交][状态][讨论版] 题目描述 大学里,最难忘的事情莫过于军训了,白白的HH童鞋就被无情 ...

  5. JS获取中文拼音首字母,并通过拼音首字母高速查找页面内的中文内容

    实现效果: 图一: 图二: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGVzdGNzX2Ru/font/5a6L5L2T/fontsize/400/f ...

  6. source code of MES Data

    <HTML> <HEAD> <TITLE>TELOGS</TITLE> </HEAD> <BODY> <?php /* c ...

  7. iOS开发- 打包ipa,让别人设备安装你的App

    一般在接外包的时候, 通常第三方须要安装你的app进行測试(这时候你的app肯定是还没传到app store之前). 这样的情况下.假设是企业账号就好办了, 随便安装.. 可是个人开发人员账号呢? 假 ...

  8. Ural 1086 - Cryptography

    While preparing this problem set the jury has run into the following problem: it was necessary to se ...

  9. 彻底理解浮动float CSS浮动详解 清除浮动的方法

    我们把网页的常用的布局格式分为以下三种: 1.标准流. 所谓的标准流就是,行内元素自己单独一行,而块级元素是上下显示的. 以前我们学习的都是标准流.   注意:标准流使我们网页布局中最稳定的一种结构 ...

  10. 转:一道笔试题-将int型数组强制转换为char*,再求strlen,涉及大小端

    写出如下程序运行结果: #include<stdio.h> #include<string.h> int main() { int a[2000]; char *p = (ch ...