Matlab影像處理(四)影像濾波
%% 平均濾波 中值濾波
close all; clear; clc;
img = double(rgb2gray(imread('A.jpg')));
[row, col] = size(img(:, :, 1));
avgimg = zeros(row, col); medimg = zeros(row, col);
count=0; A=0; s=zeros(1, 9);
for i=1:row-2
for j=1:col-2
for ii=1:3
for jj=1:3
count = count + 1;
A = A + img(i+ii-1, j+jj-1);
s(1, count) = img(i+ii-1, j+jj-1);
end
end
avgimg(i+1, j+1) = A./count;
count=0; A=0;
s = sort(s);
medimg(i+1, j+1) = s(1, 5);
s = zeros(1, 9);
end
end
subplot(1, 3, 1), imshow(uint8(img)), title('原圖')
subplot(1, 3, 2), imshow(uint8(avgimg)), title('平均濾波')
subplot(1, 3, 3), imshow(uint8(medimg)), title('中值濾波')
留言
張貼留言