pkg load image clear clc I = imread('cameraman.bmp'); I2 = uint8(zeros(256)); I3 = uint8(zeros(256)); I4 = uint8(zeros(256)); % switch rows for i = 1 : 2 : 255 I2(i,:) = I(i+1,:); I2(i+1,:) = I(i,:); endfor % switch columns for j = 1 : 2 : 255 I3(:,j) = I(:,j+1); I3(:,j+1) = I(:,j); endfor clear i, j; % switch rows and columns for i = 1 : 2 : 255 I5(i,:) = I(i+1,:); I5(i+1,:) = I(i,:); endfor for j = 1 : 2 : 255 I4(:,j) = I5(:,j+1); I4(:,j+1) = I5(:,j); endfor H5x5 = (1/25)*ones(5); Hw = (1/16)*[1 2 1; 2 4 2; 1 2 1]; I4fa = imfilter(I4, H5x5); I4fb = imfilter(I4, Hw); I4fc = ordfilt2(I4, 5, ones(3)); psnr_I_I4fa = psnr(I, I4fa, 255); psnr_I_I4fb = psnr(I, I4fb, 255); psnr_I_I4fc = psnr(I, I4fc, 255); subplot(2,3,1), imshow(I,[0 255]), title('Original') subplot(2,3,2), imshow(I4,[0 255]), title('Rows and columns switched') subplot(2,3,4), imshow(I4fa,[0 255]), title('Average filtered') subplot(2,3,5), imshow(I4fb,[0 255]), title('Weighted average filtered') subplot(2,3,6), imshow(I4fc,[0 255]), title('Median filtered')