声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 9560|回复: 10

[共享资源] [转帖]matlab下gabor滤波算法,可以提取图象纹理特征

[复制链接]
发表于 2006-5-9 22:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 1

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % 1 -1 x ^ y ^

  %%% G(x,y) = ---------- * exp ([----{(----) 2+(----) 2}+2*pi*i*(Ux+Vy)])

  % 2*pi*sx*sy 2 sx sy

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% U & V : Centre frequencies along x and y-axes respectively

  %% G : The output filter as described above

  %% gabout : The output filtered image

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function [G,gabout] = gaborfilter(I,Sx,Sy,U,V);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  G(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy))*exp(-.5*((x/Sx)^2+(y/Sy)^2)+2*pi*i*(U*x+V*y));

  end

  end

  Imgabout = conv2(I,double(imag(G)),'same');

  Regabout = conv2(I,double(real(G)),'same');

  gabout = uint8(sqrt(Imgabout.*Imgabout + Regabout.*Regabout));
回复
分享到:

使用道具 举报

 楼主| 发表于 2006-5-9 22:01 | 显示全部楼层

回复:(suffer)[转帖]matlab下gabor滤波算法,可以提...

本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 2

  %%ANOTHER DESCRIBTION OF GABOR FILTER

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % -1 x' ^ y' ^

  %%% G(x,y,theta,f) = exp ([----{(----) 2+(----) 2}])*cos(2*pi*f*x');

  % 2 sx' sy'

  %%% x' = x*cos(theta)+y*sin(theta);

  %%% y' = y*cos(theta)-x*sin(theta);

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% f : The frequency of the sinusoidal function

  %% theta : The orientation of Gabor filter

  %% G : The output filter as described above

  %% gabout : The output filtered image

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function [G,gabout] = gaborfilter(I,Sx,Sy,f,theta);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  xPrime = x * cos(theta) + y * sin(theta);

  yPrime = y * cos(theta) - x * sin(theta);

  G(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*((xPrime/Sx)^2+(yPrime/Sy)^2))*cos(2*pi*f*xPrime);

  end

  end

  Imgabout = conv2(I,double(imag(G)),'same');

  Regabout = conv2(I,double(real(G)),'same');

  gabout = sqrt(Imgabout.*Imgabout + Regabout.*Regabout);
 楼主| 发表于 2006-5-9 22:01 | 显示全部楼层

回复:(suffer)[转帖]matlab下gabor滤波算法,可以提...

本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 3

  %%ANOTHER DESCRIBTION OF GABOR FILTER

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % 1 -1 x ^ y ^

  %%% Gi(x,y) = ---------- * exp ([----{(----) 2+(----) 2}])*Mi(x,y,f);

  % 2*pi*sx*sy 2 sx sy

  %%% i =1,2

  %%% M1(x,y,f) = cos[2*pi*f*sqrt(x^2+y^2)];

  %%% M2(x,y,f) = cos[2*pi*f*(x*cos(theta) + y*sin(theta)];

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% f : The frequency of the sinusoidal function

  %% theta : The orientation of Gabor filter

  %% G1 & G2 : The output filters as described above

  %% gabout1 & gabout2 : The output filtered images

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function [G1,G2,gabout1,gabout2] = gaborfilter(I,Sx,Sy,f,theta);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  M1 = cos(2*pi*f*sqrt(x^2+y^2));

  M2 = cos(2*pi*f*(x*cos(theta)+y*sin(theta)));

  G1(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy)) * exp(-.5*((x/Sx)^2+(y/Sy)^2))*M1;

  G2(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy)) * exp(-.5*((x/Sx)^2+(y/Sy)^2))*M2;

  end

  end

  Imgabout1 = conv2(I,double(imag(G1)),'same');

  Regabout1 = conv2(I,double(real(G1)),'same');

  Imgabout2 = conv2(I,double(imag(G2)),'same');

  Regabout2 = conv2(I,double(real(G2)),'same');

  gabout1 = sqrt(Imgabout1.*Imgabout1 + Regabout1.*Regabout1);

  gabout2 = sqrt(Imgabout2.*Imgabout2 + Regabout2.*Regabout2);
发表于 2006-5-10 09:34 | 显示全部楼层

回复:(suffer)回复:(suffer)[转帖]matlab下gabo...

本帖最后由 wdhd 于 2016-9-1 14:01 编辑

  我怎么不可以运行啊 ,可以举个例子来说明一下吗?

  麻烦你了
发表于 2006-5-10 09:42 | 显示全部楼层

回复:(suffer)回复:(suffer)[转帖]matlab下gabo...

我很苯的,您可不可以以一扶图举例一下啊
发表于 2006-12-7 16:44 | 显示全部楼层
自己试一下,不是笨不笨的问题,关键是怎么理解
 楼主| 发表于 2006-12-9 09:42 | 显示全部楼层
原帖由 ld1127 于 2006-5-10 09:42 发表
我很苯的,您可不可以以一扶图举例一下啊


注释里非常清楚了,自己好好琢磨一下
发表于 2007-1-24 17:19 | 显示全部楼层

回复 #2 suffer 的帖子

第二个版本里面的参数:
%% Sx & Sy : Variances along x and y-axes respectively
这两个参数都选 1
%% f : The frequency of the sinusoidal function
这个参数选择2,4,8,16
%% theta : The orientation of Gabor filter
这个参数分别是0,45,90,135,180

作为汉字字符图像特征的提取,出来的结果简直惨不忍睹
都没有取到希望方向上的特征
请教一下是为什么呢 ?
发表于 2007-6-5 21:52 | 显示全部楼层
谢谢,刚刚学Gabor,一直看不懂。好好学习去
发表于 2009-1-11 11:01 | 显示全部楼层
感觉好像很有趣, 随意找了下! 原始资料是有例子转贴如下
I = imread('cameraman.tif');  
[G,gabout] = gaborfilter1(I,2,4,16,pi/3);  
figure,imshow(uint8(gabout));

转贴有其好处, 但原址或许亦有其他优点(许多人意见)
不过个人外行, 许多不会, 仅列联接有兴趣者或许有用!
http://www.mathworks.com/matlabcentral/fileexchange/5237
发表于 2011-5-10 16:13 | 显示全部楼层
怎么都是乱码 啊
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-24 20:12 , Processed in 0.067467 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表