clc, clearvars, close all I = imread('cameraman.tif'); IF = I; [row col] = size(I); for i = 2:row-1 for j = 2:col-1 Mask = I(i-1:i+1, j-1:j+1); Mean_mask = mean(mean(Mask)); IF(i,j) = Mean_mask; end end figure, imshow(IF), title('Mean--Filtered--Image')