【图像处理】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 ...
随机推荐
- H面试程序(16): 简单选择排序
#include<stdio.h> #include<assert.h> void display(int * a, int n) { assert(a); for(int i ...
- ceph源码之一
转自于:http://blog.csdn.net/changtao381/article/details/8698935 一.概述: 其结构如下:在src 里, 网络通信: msg 里面 包括了网 ...
- 【Eclipse】WebServiceExplorer
1.点击以下按钮启动Eclipse Web Service Explorer 2.点击页面右上角的WSDL PAGE按钮 3.点击页面左上角WSDL MAIN-->输入WSDL地址-->选 ...
- UIViewController XIB/NIB加载过程
UIViewController中关于nib初始化的函数 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBu ...
- 性能测试工具:AB
###################################################################################格式:ab -n 请求次数 -c ...
- Python实现 zip解压缩到指定目录
#!/bin/env python #-*- coding:utf-8 -*- import zipfile,os import platform,sys,os from zipfile import ...
- nginx access_log 完全关闭
最近在配置本地nginx开发环境时,发现一个问题,当server段不指定access_log时,并且http段中也未指定任何 access_log参数时,它会默认写到logs/access.log这个 ...
- js Function 加不加new 详解
以下来自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new The new operato ...
- c++ - Create empty json array with jsoncpp - Stack Overflow
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客 multiprocessing.pool c++ - Create empty json array wit ...
- HDU 4739 求正方形个数
九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...