我正在尝试在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 vs.但是当我发送3pi / 4,0,pi或2 * pi作为参数时,它只显示一条直线。我的代码有什么问题,我不明白。
答案 0 :(得分:1)
旋转变换是:
x2 = cos(theta)*(x)-sin(theta)*(y);
y2 = sin(theta)*(x)+cos(theta)*(y); % last term is not cos(theta)*(x)