- 浏览: 118365 次
文章分类
- 全部博客 (90)
- hibernate (3)
- Json java (1)
- Hibernate读书笔记 (2)
- Android (3)
- IT 生活 (2)
- ACM_HDU (1)
- 动态规划 (1)
- andriod (1)
- C++ (2)
- Hibernater (1)
- 网络流 (1)
- 杂谈 (1)
- c (1)
- 教程 (2)
- spring (2)
- 个人 (1)
- javascript (1)
- 【SQL Server】 (1)
- windows32 (1)
- GScript V6 C++脚本 (1)
- VOIP (1)
- 图论 (1)
- C# (1)
- android 面试 (1)
- Segment Tree(线段树) (1)
- SSH (1)
- SQL (1)
- Web前端 (1)
- linux (1)
- java (1)
- 网站公告 (1)
- 【Android开发学习之路】 (1)
- 业界 (1)
- UNIX技术 (1)
- Matlab (1)
- .NET (1)
- PLC自动化 (1)
- Mega ADK (1)
- html (1)
- HTML5 (1)
- UtilBox基础组件 (1)
- Algorithms (1)
- iOS Game开发笔记 (1)
最新评论
-
di1984HIT:
学习了,写的好~
FreeMarker + xml 导出word -
IT_Dodo:
按你写的Demo写了 可跑不起来哈,.,.... 报(data ...
easyUI 展开DataGrid里面的行显示详细信息 -
无象心:
有没有考虑过word xml转换成真正的word,求教!
FreeMarker + xml 导出word -
aijuans:
这个不错,值得参考
FreeMarker + xml 导出word -
lucky16:
最後那個優缺點對比可以留做參考
FreeMarker + xml 导出word
方式一:
function result = gaborKernel2d( lambda, theta, phi, gamma, bandwidth) % GABORKERNEL2D % Version: 2012/8/17 by watkins.song % Version: 1.0 % Fills a (2N+1)*(2N+1) matrix with the values of a 2D Gabor function. % N is computed from SIGMA. % % LAMBDA - preferred wavelength (period of the cosine factor) [in pixels] % SIGMA - standard deviation of the Gaussian factor [in pixels] % THETA - preferred orientation [in radians] % PHI - phase offset [in radians] of the cosine factor % GAMMA - spatial aspect ratio (of the x- and y-axis of the Gaussian elipse) % BANDWIDTH - spatial frequency bandwidth at half response, % ******************************************************************* % % BANDWIDTH, SIGMA and LAMBDA are interdependent. To use BANDWIDTH, % the input value of one of SIGMA or LAMBDA must be 0. Otherwise BANDWIDTH is ignored. % The actual value of the parameter whose input value is 0 is computed inside the % function from the input vallues of BANDWIDTH and the other parameter. % % pi -1 x'^2+gamma^2*y'^2 % G(x,y,theta,f) = --------------- *exp ([----{-------------------}])*cos(2*pi*f*x'+phi); % 2*sigma*sigma 2 sigma^2 % %%% x' = x*cos(theta)+y*sin(theta); %%% y' = y*cos(theta)-x*sin(theta); % % Author: watkins.song % Email: watkins.song@gmail.com % calculation of the ratio sigma/lambda from BANDWIDTH % according to Kruizinga and Petkov, 1999 IEEE Trans on Image Processing 8 (10) p.1396 % note that in Matlab log means ln slratio = (1/pi) * sqrt( (log(2)/2) ) * ( (2^bandwidth + 1) / (2^bandwidth - 1) ); % calcuate sigma sigma = slratio * lambda; % compute the size of the 2n+1 x 2n+1 matrix to be filled with the values of a Gabor function % this size depends on sigma and gamma if (gamma <= 1 && gamma > 0) n = ceil(2.5*sigma/gamma); else n = ceil(2.5*sigma); end % creation of two (2n+1) x (2n+1) matrices x and y that contain the x- and y-coordinates of % a square 2D-mesh; the rows of x and the columns of y are copies of the vector -n:n [x,y] = meshgrid(-n:n); % change direction of y-axis (In Matlab the vertical axis corresponds to the row index % of a matrix. If the y-coordinates run from -n to n, the lowest value (-n) comes % in the top row of the matrix ycoords and the highest value (n) in the % lowest row. This is oposite to the customary rendering of values on the y-axis: lowest value % in the bottom, highest on the top. Therefore the y-axis is inverted: y = -y; % rotate x and y % xp and yp are the coordinates of a point in a coordinate system rotated by theta. % They are the main axes of the elipse of the Gaussian factor of the Gabor function. % The wave vector of the Gabor function is along the xp axis. xp = x * cos(theta) + y * sin(theta); yp = -x * sin(theta) + y * cos(theta); % precompute coefficients gamma2=gamma*gamma, b=1/(2*sigma*sigma) and spacial frequency % f = 2*pi/lambda to prevent multiple evaluations gamma2 = gamma*gamma; b = 1 / (2*sigma*sigma); a = b / pi; f = 2*pi/lambda; % filling (2n+1) x (2n+1) matrix result with the values of a 2D Gabor function result = a*exp(-b*(xp.*xp + gamma2*(yp.*yp))) .* cos(f*xp + phi); %%%%%%%% NORMALIZATION %%%%%%%%%%%%%%%%%%%% % NORMALIZATION of positive and negative values to ensure that the integral of the kernel is 0. % This is needed when phi is different from pi/2. ppos = find(result > 0); %pointer list to indices of elements of result which are positive pneg = find(result < 0); %pointer list to indices of elements of result which are negative pos = sum(result(ppos)); % sum of the positive elements of result neg = abs(sum(result(pneg))); % abs value of sum of the negative elements of result meansum = (pos+neg)/2; if (meansum > 0) pos = pos / meansum; % normalization coefficient for negative values of result neg = neg / meansum; % normalization coefficient for psoitive values of result end result(pneg) = pos*result(pneg); result(ppos) = neg*result(ppos); end
方式二:
function [Efilter, Ofilter, gb] = gaborKernel2d_evenodd( lambda, theta, kx, ky) %GABORKERNEL2D_EVENODD Summary of this function goes here % Usage: % gb = spatialgabor(im, wavelength, angle, kx, ky, showfilter) % Version: 2012/8/17 by watkins.song % Version: 1.0 % % Arguments: % im - Image to be processed. % wavelength - Wavelength in pixels of Gabor filter to construct % angle - Angle of filter in degrees. An angle of 0 gives a % filter that responds to vertical features. % kx, ky - Scale factors specifying the filter sigma relative % to the wavelength of the filter. This is done so % that the shapes of the filters are invariant to the % scale. kx controls the sigma in the x direction % which is along the filter, and hence controls the % bandwidth of the filter. ky controls the sigma % across the filter and hence controls the % orientational selectivity of the filter. A value of % 0.5 for both kx and ky is a good starting point. % % lambda = 3; % theta = 90; % kx = 0.5; % ky = 0.5; % % % Author: watkins.song % Email: watkins.song@gmail.com % Construct even and odd Gabor filters sigmax = lambda*kx; sigmay = lambda*ky; sze = round(3*max(sigmax,sigmay)); [x,y] = meshgrid(-sze:sze); evenFilter = exp(-(x.^2/sigmax^2 + y.^2/sigmay^2)/2).*cos(2*pi*(1/lambda)*x); % the imaginary part of the gabor filter oddFilter = exp(-(x.^2/sigmax^2 + y.^2/sigmay^2)/2).*sin(2*pi*(1/lambda)*x); evenFilter = imrotate(evenFilter, theta, 'bilinear','crop'); oddFilter = imrotate(oddFilter, theta, 'bilinear','crop'); gb = evenFilter; Efilter = evenFilter; Ofilter = oddFilter; end
方式三:
function gb = gaborKernel2d_gaborfilter( lambda, theta, phi, gamma, bw) %GABORKERNEL2D_GABORFILTER Summary of this function goes here % Version: 2012/8/17 by watkins.song % Version: 1.0 % % LAMBDA - preferred wavelength (period of the cosine factor) [in pixels] % SIGMA - standard deviation of the Gaussian factor [in pixels] % THETA - preferred orientation [in radians] % PHI - phase offset [in radians] of the cosine factor % GAMMA - spatial aspect ratio (of the x- and y-axis of the Gaussian elipse) % BANDWIDTH - spatial frequency bandwidth at half response, % ******************************************************************* % % BANDWIDTH, SIGMA and LAMBDA are interdependent. To use BANDWIDTH, % the input value of one of SIGMA or LAMBDA must be 0. Otherwise BANDWIDTH is ignored. % The actual value of the parameter whose input value is 0 is computed inside the % function from the input vallues of BANDWIDTH and the other % parameter. % -1 x'^2 + y'^2 %%% G(x,y,theta,f) = exp ([----{-----------------})*cos(2*pi*f*x'+phi); % 2 sigma*sigma %%% x' = x*cos(theta)+y*sin(theta); %%% y' = y*cos(theta)-x*sin(theta); % % Author: watkins.song % Email: watkins.song@gmail.com % bw = bandwidth, (1) % gamma = aspect ratio, (0.5) % psi = phase shift, (0) % lambda= wave length, (>=2) % theta = angle in rad, [0 pi) sigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1); sigma_x = sigma; sigma_y = sigma/gamma; sz=fix(8*max(sigma_y,sigma_x)); if mod(sz,2)==0 sz=sz+1; end % alternatively, use a fixed size % sz = 60; [x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2)); % x (right +) % y (up +) % Rotation x_theta = x*cos(theta)+y*sin(theta); y_theta = -x*sin(theta)+y*cos(theta); gb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+phi); end
方式四:
function gb = gaborKernel2d_wiki( lambda, theta, phi, gamma, bandwidth) % GABORKERNEL2D_WIKI 改写的来自wiki的gabor函数 % Version: 2012/8/17 by watkins.song % Version: 1.0 % % LAMBDA - preferred wavelength (period of the cosine factor) [in pixels] % SIGMA - standard deviation of the Gaussian factor [in pixels] % THETA - preferred orientation [in radians] % PHI - phase offset [in radians] of the cosine factor % GAMMA - spatial aspect ratio (of the x- and y-axis of the Gaussian elipse) % BANDWIDTH - spatial frequency bandwidth at half response, % ******************************************************************* % % BANDWIDTH, SIGMA and LAMBDA are interdependent. To use BANDWIDTH, % the input value of one of SIGMA or LAMBDA must be 0. Otherwise BANDWIDTH is ignored. % The actual value of the parameter whose input value is 0 is computed inside the % function from the input vallues of BANDWIDTH and the other % parameter. % -1 x'^2 + y'^2 %%% G(x,y,theta,f) = exp ([----{-----------------})*cos(2*pi*f*x'+phi); % 2 sigma*sigma %%% x' = x*cos(theta)+y*sin(theta); %%% y' = y*cos(theta)-x*sin(theta); % % Author: watkins.song % Email: watkins.song@gmail.com % calculation of the ratio sigma/lambda from BANDWIDTH % according to Kruizinga and Petkov, 1999 IEEE Trans on Image Processing 8 (10) p.1396 % note that in Matlab log means ln slratio = (1/pi) * sqrt( (log(2)/2) ) * ( (2^bandwidth + 1) / (2^bandwidth - 1) ); % calcuate sigma sigma = slratio * lambda; sigma_x = sigma; sigma_y = sigma/gamma; % Bounding box nstds = 4; xmax = max(abs(nstds*sigma_x*cos(theta)),abs(nstds*sigma_y*sin(theta))); xmax = ceil(max(1,xmax)); ymax = max(abs(nstds*sigma_x*sin(theta)),abs(nstds*sigma_y*cos(theta))); ymax = ceil(max(1,ymax)); xmin = -xmax; ymin = -ymax; [x,y] = meshgrid(xmin:xmax,ymin:ymax); % Rotation x_theta = x*cos(theta) + y*sin(theta); y_theta = -x*sin(theta) + y*cos(theta); % Gabor Function gb= exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+phi); end
方式五:
function [GaborReal, GaborImg] = gaborKernel_matlab( GaborH, GaborW, U, V, sigma) %GABORKERNEL_MATLAB generate very beautiful gabor filter % Version: 2012/8/17 by watkins.song % Version: 1.0 % 用以生成 Gabor % GaborReal: 核实部 GaborImg: 虚部 % GaborH,GaborW: Gabor窗口 高宽. % U,V: 方向 大小 % ||Ku,v||^2 % G(Z) = ---------------- exp(-||Ku,v||^2 * Z^2)/(2*sigma*sigma)(exp(i*Ku,v*Z)-exp(-sigma*sigma/2)) % sigma*sigma % % 利用另外一个gabor函数来生成gabor filter, 通过u,v表示方向和尺度. % 这里的滤波器模板的大小是不变的,变化的只有滤波器的波长和方向 % v: 代表波长 % u: 代表方向 % 缺省输入前2个参数,后面参数 Kmax=2.5*pi/2, f=sqrt(2), sigma=1.5*pi; % GaborH, GaborW, Gabor模板大小 % U,方向因子{0,1,2,3,4,5,6,7} % V,大小因子{0,1,2,3,4} % Author: watkins.song % Email: watkins.song@gmail.com HarfH = fix(GaborH/2); HarfW = fix(GaborW/2); Qu = pi*U/8; sqsigma = sigma*sigma; Kv = 2.5*pi*(2^(-(V+2)/2)); %Kv = Kmax/(f^V); postmean = exp(-sqsigma/2); for j = -HarfH : HarfH for i = -HarfW : HarfW tmp1 = exp(-(Kv*Kv*(j*j+i*i)/(2*sqsigma))); tmp2 = cos(Kv*cos(Qu)*i+Kv*sin(Qu)*j) - postmean; %tmp3 = sin(Kv*cos(Qu)*i+Kv*sin(Qu)*j) - exp(-sqsigma/2); tmp3 = sin(Kv*cos(Qu)*i+Kv*sin(Qu)*j); GaborReal(j+HarfH+1, i+HarfW+1) = Kv*Kv*tmp1*tmp2/sqsigma; GaborImg(j+HarfH+1, i+HarfW+1) = Kv*Kv*tmp1*tmp3/sqsigma; end end end
最后调用方式都一样:
% 测试用程序 theta = [0 pi/8 2*pi/8 3*pi/8 4*pi/8 5*pi/8 6*pi/8 7*pi/8]; lambda = [4 6 8 10 12]; phi = 0; gamma = 1; bw = 0.5; % 计算每个滤波器 figure; for i = 1:5 for j = 1:8 gaborFilter=gaborKernel2d(lambda(i), theta(j), phi, gamma, bw); % 查看每一个滤波器 %figure; %imshow(real(gaborFilter),[]); % 将所有的滤波器放到一张图像中查看,查看滤波器组 subplot(5,8,(i-1)*8+j); imshow(real(gaborFilter),[]); end end
相关推荐
本篇文章将深入探讨如何使用Matlab来实现Gabor滤波器,以及如何利用它来提取图像的纹理特征。 Gabor滤波器基于Gabor函数,这是一种复数带通滤波器,可以同时考虑空间和频率信息。其数学表达式为: \[ G(x, y; \...
MATLAB作为一种强大的数值计算和可视化软件,提供了方便的环境来实现Gabor滤波器。本资源包含的"run3.m"和"run4.m"可能是两个MATLAB脚本,用于演示或执行Gabor滤波器的代码。 Gabor滤波器的核心概念是基于Gabor函数...
这一步骤可以通过创建Gabor滤波器组,然后对每个像素进行滤波来实现。 4. **一维向量化**:滤波后的二维矩阵会被展平为一维向量,便于后续的处理和分析。这通常通过使用MATLAB的`reshape`或`squeeze`函数完成。 5....
标题“gabor.zip_Gabor filter_MATLAB gabor_gabor_gabor filter matlab_ga”暗示了这个压缩包包含与MATLAB相关的Gabor滤波器代码或者教程。 描述中的“gabor filter for matlab 7.1”表明资源是为MATLAB 7.1(R...
"matlab_gabor gabor gabor___matlab gabor_matlab"这些标签可能表示压缩包包含了不同版本或实现方式的Gabor滤波代码,可能有不同优化或特定功能的实现,例如多尺度或多方向的Gabor滤波。 总的来说,这个名为"Gabor...
Gabor Filter,LabVIEW实现
【图像增强】基于matlab GUI gabor滤波器指纹增强技术是数字图像处理中的一个重要领域,主要用于提升指纹图像的质量,以便于识别和分析。在本项目中,MATLAB被用作开发工具,GUI(图形用户界面)使得操作更加直观...
Gabor滤波器的源码,基于matlab。可以适用于图形图像的Gabor变换。
时频分析 Gabor 变换 Matlab程序
本资源是基于MATLAB实现的Gabor滤波器,名为"Gabor Matlab.zip",其中包含了亲测可用并可以直接运行的代码。"Gabor filter"是核心算法,"MATLAB gabor"表示这些代码是用MATLAB编程语言编写的,"fingeroh6_gabor_kept...
资源名:二维图像Gabor滤波源代码_gaborfilter_matlab 资源类型:matlab项目全套源码 源码说明: 全部项目源码都是经过测试校正后百分百成功运行的,如果您下载后不能运行可联系我进行指导或者更换。 适合人群:新手...
本资源包提供的内容聚焦于利用MATLAB实现2D-Gabor滤波器进行虹膜的特征编码。下面将详细介绍这个过程以及相关知识点。 首先,我们要了解虹膜识别的基本原理。虹膜是人眼瞳孔周围的环状区域,具有丰富的纹理结构,...
二维Gabor滤波器的实现 matlab代码 直接运行即可 尺度和方向均可自己设置
在本文中,我们将深入探讨如何使用MATLAB中的Gabor变换和神经网络技术来实现人脸识别。MATLAB是一款强大的数值计算和编程环境,非常适合进行图像处理和机器学习任务,如人脸识别。 人脸识别是一项复杂的技术,旨在...
本篇文章将详细讲解Gabor滤波的原理以及如何使用MATLAB进行实现,同时结合提供的两个文件`test.m`和`MakeGaborKernal.m`来解析其实现过程。 Gabor滤波器的理论基础源于信号处理,它结合了傅立叶变换和空间滤波的...
3种Gabor滤波器的表达方法,采用MATLAB编写,可用于人脸的识别
Gabor特征提取MATLAB函数 function gaborArray = gaborFilterBank(u,v,m,n) function featureVector = gaborFeatures(img,gaborArray,d1,d2)
总的来说,Gabor特征提取在MATLAB中的实现是一种高效且灵活的方法,适用于图像识别、物体检测、纹理分析等多种场景。其优点在于能够在保持局部信息的同时,提取出图像的频域特性,对于处理具有复杂纹理和边缘的图像...
2. **滤波操作**:使用生成的Gabor滤波器对图像进行卷积操作,这可以通过MATLAB的`filter2`或`conv2`函数完成。滤波通常在四个主要方向(0°, 45°, 90°, 135°)上进行,以捕捉不同方向的特征。 3. **参数选择**...
本文将深入探讨Gabor滤波器的原理,以及如何在MATLAB环境中实现Gabor特征的提取。 Gabor滤波器的原理: Gabor滤波器是一种线性带通滤波器,由Gabor函数定义,其形式为复数高斯函数乘以正弦函数。这种滤波器可以同时...