【图像处理】Gabor过滤器
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过滤器的更多相关文章
- Deep Neural Networks for Object Detection(翻译)
0 - Abstract 深度神经网络(DNNs)最近在图像分类任务上表现出了突出的性能.在这篇文章中,我们进一步深入探究使用DNNs进行目标检测的问题,这个问题不仅需要对物体进行分类,并且还需要对各 ...
- Topographic ICA as a Model of Natural Image Statistics(作为自然图像统计模型的拓扑独立成分分析)
其实topographic independent component analysis 早在1999年由ICA的发明人等人就提出了,所以不算是个新技术,ICA是在1982年首先在一个神经生理学的背景 ...
- PReLU——Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification
1. 摘要 在 \(ReLU\) 的基础上作者提出了 \(PReLU\),在几乎没有增加额外参数的前提下既可以提升模型的拟合能力,又能减小过拟合风险. 针对 \(ReLU/PReLU\) 的矫正非线性 ...
- 图像处理之滤波---gabor
http://blog.csdn.net/xiaowei_cqu/article/details/24745945 小魏北大
- 共有31款PHP 图形/图像处理开源软件(转)
详情点击:http://www.oschina.net/project/lang/22/php?tag=141&os=0&sort=view PHP 图像处理库 Grafika Gra ...
- paper 119:[转]图像处理中不适定问题-图像建模与反问题处理
图像处理中不适定问题 作者:肖亮博士 发布时间:09-10-25 图像处理中不适定问题(ill posed problem)或称为反问题(inverse Problem)的研究从20世纪末成为国际上的 ...
- opencv6.1-imgproc图像处理模块之平滑与形态学操作
这个部分是<opencv-tutorials.pdf>的部分,这部分也是几大部分中例子最多的,其实这个教程的例子都很不错,不过有些看得出来还是c接口的例子,说明例子有些年头了,其实在&qu ...
- opencv6.2-imgproc图像处理模块之图像尺寸上的操作及阈值
接opencv6.1-imgproc图像处理模块之平滑和形态学操作,顺带说一句在opencv中的in-place操作就是比如函数的输入图像和输出图像两个指针是相同的,那么就是in-place操作了.比 ...
- opencv6.3-imgproc图像处理模块之边缘检测
接opencv6.2-improc图像处理模块之图像尺寸上的操作 本文大部分都是来自于转http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutori ...
随机推荐
- python and 和 or
在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样.但是它们并不返回布尔值,而是返回它们实际进行比较的值之一. 例 4.15. and 介绍 >>> 'a' a ...
- Uva 225 Golygons
这道题如果直接用Dfs,运气好的话是可以直接过的. 但如果要在Dfs的基础上加快速度,剪枝是必不可少的. 我的剪枝策略: 1.当前点(x,y)回到出发点至少需要 |x| +| y| 步,如果剩余的步数 ...
- jQuery遍历table
1. $("table").find("tr").each(function(){ $(this).find("td").each(func ...
- ViewPager实现广告自动轮播核心代码(Handler+Thread)
ViewPager数据源是4个线性布局,每个布局里面充满一张高度固定.宽度充满父布局的图片.有4个小圆点跟随ViewPager滑动.轮播原本我是用Timer+TimerTask的,但是问题颇多,很是郁 ...
- 驱动: 中断【1】linux中断流程
通常情况下,当一个给定的中断处理程序正在执行时,所有其他的中断都是打开的,所以这些不同中断线上的其他中断都能被处理,但当前中断总是被禁止的. 将中断处理切为两个部分或两半.中断处理程序上半部(top ...
- CSS 实现图片灰度效果 兼容各种浏览器
CSS 实现图片灰度效果 兼容各种浏览器如360浏览器 CSS实现图片灰度效果就是通过CSS样式让彩色图片呈现为灰色,相当于把一张图像的颜色模式调整为灰度,CSS可以通过以下几种方法来实现灰度效果. ...
- 纯JAVA驱动:sqlserver版本不同,驱动与连接也有所区别
纯JAVA驱动:// 2005 版本:驱动:Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");连接:”jd ...
- docker学习笔记7:发布镜像到docker hub上
镜像创建好后,很重要的一个操作就是共享和发布.可以将自己创建的镜像发布到docker hub上,也可以发布到自己的私有docker hub上. 要想发布镜像到dokcer hub上,首先要在dokce ...
- zk leader选举自动完成
server 1: [root@wx03 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /zook ...
- 进入MFC讲坛的前言(二)
MFC的WinMain 使用MFC编程的程序员刚开始都会提出这样一个问题:我的程序是从哪儿开始执行的?回答是:从WinMain()开始执行的.提出这样的问题是由于在他们所编写的MFC应用中看不到Win ...