Computer Vision_Matlab (4)

这篇博客介绍了如何利用Gabor滤波器对图像进行处理,分别展示了简单细胞(SimpleCells)和复杂细胞(ComplexCells)的实现。通过调用gabor2函数生成Gabor核,然后应用卷积操作来提取图像特征。简单细胞部分展示了单一方向的滤波结果,而复杂细胞部分则结合了两个不同相位的Gabor滤波器,通过平方和运算得到图像的特征响应。代码中给出了具体的参数设置和结果示例。
摘要由CSDN通过智能技术生成

1 Simple Cells

Ia = imread ('elephant.png');
Ia = im2double(Ia);

v1 = gabor2 (3,0.1,90,0.75,90);
Ia_gabor2 = conv2 (Ia, v1, 'valid');

figure(1), clf,imagesc(Ia_gabor2); axis('equal','tight'), colormap('gray'); colorbar

2 Complex Cells

gA=gabor2(3,0.1,90,0.75,90);
gB=gabor2(3,0.1,90,0.75,0);
IgA=conv2(Ia,gA,'valid');
IgB=conv2(Ia,gB,'valid');
Ia_AB=sqrt((IgA.^2)+(IgB.^2));
figure(2), clf, imagesc(Ia_AB); axis('equal','tight'), colormap('gray'); colorbar;

Code

%% Code

%% Simple cells
Ia = imread ('elephant.png');
Ia = im2double(Ia);

v1 = gabor2 (3,0.1,90,0.75,90);
Ia_gabor2 = conv2 (Ia, v1, 'valid');

figure(1), clf,imagesc(Ia_gabor2); axis('equal','tight'), colormap('gray'); colorbar
Ia_gabor2 (360, 414)
Ia_gabor2 (276, 208)

%% Complex cells
gA=gabor2(3,0.1,90,0.75,90);
gB=gabor2(3,0.1,90,0.75,0);
IgA=conv2(Ia,gA,'valid');
IgB=conv2(Ia,gB,'valid');
Ia_AB=sqrt((IgA.^2)+(IgB.^2));
figure(2), clf, imagesc(Ia_AB); axis('equal','tight'), colormap('gray'); colorbar;
Ia_AB (223, 192)
Ia_AB (395, 240)

%% gabor2 function

function gb=gabor2(sigma,freq,orient,aspect,phase)
%function gb=gabor2(sigma,freq,orient,aspect,phase)
%
% This function produces a numerical approximation to 2D Gabor function.
% Parameters:
% sigma  = standard deviation of Gaussian envelope, this in-turn controls the
%          size of the result (pixels)
% freq   = the frequency of the sin wave (1/pixels)
% orient = orientation of the Gabor from the horizontal (degrees)
% aspect = aspect ratio of Gaussian envelope (1 = circular symmetric envelope,
%          lower values produce longer functions)
% phase  = the phase of the sin wave (degrees)

sz=fix(7*sigma./max(0.2,aspect));
if mod(sz,2)==0, sz=sz+1; end
 
[x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(-sz/2):fix(sz/2));
 
% Rotation 
orient=(orient-90)*pi/180;
xDash=x*cos(orient)+y*sin(orient);
yDash=-x*sin(orient)+y*cos(orient);

phase=phase*pi/180;

gb=exp(-.5*((xDash.^2/sigma^2)+(aspect^2*yDash.^2/sigma^2))).*(cos(2*pi*xDash*freq+phase));

%ensure gabor sums to zero (so it is a valid differencing mask)
gb(gb>0)=gb(gb>0)./sum(sum(max(0,gb)));
gb(gb<0)=gb(gb<0)./sum(sum(max(0,-gb)));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值