Gabor滤波器代码错误

问题描述:

编辑:Gabor滤波器的描述Gabor滤波器代码错误

 
% gab2d: **2D Gabor filter** 

% The Gabor filter is basically a Gaussian, modulated by a complex sinusoid 
% G = gab2d(I,Sx,Sy,f,theta,FUN) 


% Input and output arguments ([]'s are optional): 
% I (matrix) of size NxM: Input Image of size NxM. 
gamma (scalar): The spatial aspect ratio, x to y. 
lambda(scalar): The wavelength of the sinusoidal function. 
b (scalar): The spatial frequency band-width (in octaves) 
theta (scalar): The orientation of the gabor filter. 
% phi (scalar): The phase offset. 0 is real part of Gabor filter or 
% even-symmetric, pi/2 is imaginary part of Gabor filter or 
% odd-symmetric. 

% **Note**: 

sigma (scalar): The spread of Gabor filter or the standard 
% deviation of Gaussian is automatically computed from lambda and b. 
% [shape] (strings): Shape for conv2. See help conv2. Default is 'same'. 
% % GO (matrix) of size NxM: Output images which was applied Gabor 
% filters. This is the magnitude response. 
% [GF] (matrix) of size (2Sx+1)x(2Sy+1): Gabor filter. 
function [GO, GF] = gab2d(I, gamma, lambda, b, theta, phi, shape) 

I=imread('C:\Users\Vinay\Documents\MATLAB\textureflawimages\text9.png'); 

gamma = 1; b = 1; theta = 0:pi/6:pi-pi/6; phi = 0; shape = 'valid'; lambda=8; 

if nargin < 7, shape = 'same'; end; 

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

sigma = (1/pi) * sqrt(log(2)/2) * (2^b+1)/(2^b-1) * lambda; 

Sy = sigma * gamma; 

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

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

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

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

     GF(fix(Sy)+y+1,fix(sigma)+x+1) = ... 

     exp(-.5*(xp^2+gamma^2*yp^2)/sigma^2) * cos(2*pi*xp/lambda+phi) ... 

     ; %/ (2*pi*(sigma^2/gamma)); 

     % Normalize if you use different sigma (lambda or b) 
    end 
end 
GO = conv2(I, double(GF), shape); 

错误:

??? Error using ==> mpower Matrix must be square.

Error in ==> gab2d at 36 GF(fix(Sy)+y+1,fix(sigma)+x+1) = ...

我不知何故无法纠正这个问题..

请帮忙

+0

那是什么语言?另外,是否可以整理格式以使其更具可读性? – FrustratedWithFormsDesigner

+0

是的,它在MATLAB中这样做 – vini

theta是一个数组。因此,例如xp也是一个数组。如果你想广场xp每一个元素,那么你就需要使用元素方面的运营商,如.^电源,或.*乘法。

为了更快速地找出什么是错的,设置调试器停止每当通过在命令行中输入dbstop if error是一个错误。这允许您通过鼠标悬停在编辑器上来检查编辑器中的所有变量,并评估复杂表达式的小部分以缩小错误。