【图像处理】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 ...
随机推荐
- Android Dalvik 虚拟机
简介 Android 平台虽然是使用java语言来开发应用程序,但Android程序却不是运行在标准java虚拟机上的.谷歌专门为Android平台设计了一套虚拟机来运行Android程序.它就是Da ...
- Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral
B. Maximal Area Quadrilateral time limit per test 1 second memory limit per test 256 megabytes input ...
- HDU 4720 Naive and Silly Muggles (外切圆心)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Android:源码环境下移植第三方的apk内置到ROM(System Image)中
1. 首先在vendor目录下新建一个the3rdapk的目录,将需要内置的apk丢进去,目录名自己随意定. 2. 在 build/target/product/common.mk最后面,在$(cal ...
- linux脚本:ftp自动传输文件
使用Shell脚本实现ftp的自动上传下载 http://liwenge.iteye.com/blog/566515 open 192.168.1.171 user guest 123456cd /h ...
- BZOJ 2431: [HAOI2009]逆序对数列( dp )
dp(i,j)表示1~i的全部排列中逆序对数为j的个数. 从1~i-1的全部排列中加入i, 那么可以产生的逆序对数为0~i-1, 所以 dp(i,j) = Σ dp(i-1,k) (j-i+1 ≤ k ...
- LOVEU
闲来无事,自己编写一个小程序,自娱自乐 //date: 2013/8/14 //designer :pengxiaoen //function : printf the word love #incl ...
- Python函数式编程:Lambda表达式
首先我们要明白在编程语言中,表达式和语句的区别. 表达式是一个由变量.常量.有返回值的函数加运算符组成的一个式子,该式子是有返回值的 ,如 a + 1 就是个表达式, 单独的一个常量.变量 或函数调 ...
- 转:Bootstrap研究 精巧的网格布局系统
本网格布局系统属于Scaffolding(框架,布局)部分.在Scaffolding里面有(固定)网格布局(Grid System)和流式网格布局(Fluid Grid System).本文讨论第一种 ...
- 进入MFC讲坛的前言(一)
在这里,我想谈谈自己学习MFC的一些体会.我是从1997年才开始在Window下编写程序的.在这之前,我编写过一些DOS程序,包括一个简单的全屏幕编辑器和一个带函数的表达式解释器,都是一些小的程序.W ...