Computer Vision_Matlab (4)

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)));

### 如何在MATLAB中安装和配置Computer Vision Toolbox #### 安装步骤概述 为了在MATLAB中使用Computer Vision Toolbox的功能,可以通过官方渠道下载并安装工具箱。如果需要额外支持OpenCV或其他第三方库,则需进一步完成特定的集成操作。 #### 使用内置Computer Vision Toolbox MATLAB自带的Computer Vision Toolbox提供了丰富的图像处理与计算机视觉功能。要启用此工具箱,只需确保已购买并激活相应的许可证[^1]。 通过以下方式验证是否已安装: ```matlab ver % 查看当前MATLAB环境中所有可用工具箱列表 ``` 若未发现`Computer Vision Toolbox`,则可通过MathWorks账户重新获取许可或联系技术支持团队解决。 #### 配置OpenCV接口 当希望扩展MATLAB的能力至外部C++库(如OpenCV),可以按照如下方法设置环境变量以及加载必要的函数模块[^2]: - 下载 `Computer Vision Toolbox Interface for OpenCV in MATLAB` 并解压到本地磁盘; - 将路径添加至MATLAB全局搜索范围之内,并确认编译器兼容性良好以便顺利运行测试脚本; #### Piotr’s Computer Vision Matlab Toolbox 的补充作用 对于某些高级需求而言,单独依靠标准发行版可能不足以为用户提供足够的灵活性或者效率提升空间。此时引入开源项目成为一种可行方案之一——即采用由加州大学圣地亚哥分校开发维护的一套轻量级框架作为辅助手段来弥补差距[^4]。 具体做法包括但不限于访问官方网站下载最新版本源码包、依照指示文档逐步调整系统参数直至最终生效为止[^5]: ##### 关键点提示 - **依赖关系管理**: 确认目标平台满足最低硬件/软件规格要求之前不要贸然行动; - **权限控制机制**: 如果遇到任何关于读写受限区域报错现象, 可尝试切换工作目录再试一次; ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值