这不是重复的问题,因为不允许使用任何内置函数。谢谢。
这是我的代码,用于创建5 x 5平均滤波器,这应允许我使图像平滑,以使图像的噪点更少。我希望有人能把我带到正确的方向,因为我不确定哪里出了问题。该图像将不会显示任何错误,但是返回的图像是带有黑边的白框。
I = imread('Noisy.png');
figure;
imshow(I);
%reading in the image png file
Igray = rgb2gray(I);
figure;
imshow(Igray);
%Converting the image to grayscale
figure;
I2 = 255 * im2double(Igray);
input = padarray(I2, [2 2]);
output = zeros(size(input));
[x,y]= size(output);
%loop through image and apply smoothing filter
sum = 0;
for row = 3:x-2
for col = 3:y-2
for rowmax = row-2:row+2
for colmax = col-2:col+2
sum = sum + (1/25)*input(rowmax,colmax);
end
end
output(row,col) = sum/255;
end
end
imshow(output);