M=imread("C:\Users\user\Desktop\color.jpg"); %读取图像
[ROW,COL, DIM] = size(M);%保存图像尺寸
subplot(3,3,1),imshow(M),title('original');%显示原始图像
P1=imnoise(M,'gaussian',0.05); %加入高斯躁声
subplot(3,3,2),imshow(P1),title('gaussian noise');%加入高斯躁声后显示图像
P1=im2double(P1);
guss_filter_img=P1;
for r = 2:1:ROW-1
for c = 2:1:COL-1
for d =1:3
guss_filter_img(r,c,d) =(P1(r-1, c-1,d) + P1(r-1, c,d)*2 + P1(r-1, c+1,d) +...
P1(r, c-1,d)*2 + P1(r, c,d)*4 + P1(r, c+1,d)*2+...
P1(r+1, c-1,d) + P1(r+1, c,d)*2 + P1(r+1, c+1,d))/ 16;
end
end
end
subplot(3,3,3),imshow(guss_filter_img),title('guss_img');
M=imread("C:\Users\user\Desktop\color.jpg"); %读取图