2013-04-20 90 views
0

我想在matlab中创建和旋转高斯滤波器。这里是我的代码:在matlab中旋转高斯滤波器

function f = createGaussianArray(length, sigma, theta) 
    half = length/2; 
    [x,y] = meshgrid(-half:half, -half:half); 
    x2 = cos(theta)*(x)-sin(theta)*(y); 
    y2 = sin(theta)*(x)+cos(theta)*(x); 
    matrix = exp(- (x2.^2+y2.^2)/(2*sigma.^2)); 
    f = matrix ./ sum(matrix(:)); 
end 

当我调用此函数(函数在gauss.m文件):

filter = gauss(31, 10, pi/2); 
imagesc(filter) 

它非常适用PI/3,PI/6与然而,当我发送3pi/4,0,pi或2 * pi作为参数,它只显示一条直线。我的代码有什么问题,我不明白。

回答

1

旋转变换是:

x2 = cos(theta)*(x)-sin(theta)*(y); 
y2 = sin(theta)*(x)+cos(theta)*(y); % last term is not cos(theta)*(x) 
+0

当我做到这一点不旋转,高斯滤波器仍然是任何THETA价值 – otp 2013-04-20 18:46:19

+0

@otp你们是不是要旋转内核一样吗?高斯滤波器本身就是径向对称的。 – Justin 2013-04-20 18:49:34