matlab对图像进行低通滤波处理

matlab中运行时显示“索引超出矩阵维度”怎么解决?求大神帮忙

代码如下:

clear
clc
img=imread('2.jpg');
subplot(2,2,1);imshow(img);title('原图');
f=rgb2gray(img);    %对于RGB图像必须做的一步,也可以用im2double函数
F=fft2(f);          %傅里叶变换
F1=log(abs(F)+1);   %取模并进行缩放
subplot(2,2,2);imshow(F1,[]);title('傅里叶变换频谱图');
[a,b] = size(img);

a0 = round(a/2);

b0 = round(b/2);

d = min(a0,b0)/12;

d = d^2;

for i=1:a

for j=1:b

distance = (i-a0)^2+(j-b0)^2;

if distance

h = 1;

else

h = 0;

end

low_filter(i,j) = h*F(i,j);

end

end

subplot(2,2,4),imshow(log(abs(low_filter)),[])

title('低通滤波频谱');

new_img = uint8(real(ifft2(ifftshift(low_filter))));

subplot(2,2,2),imshow(new_img,[])

title('低通滤波后的图像');


 

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。