pkg load image clear clc I = imread('Lena256color.jpg'); I2 = I; for i = 1 : 256 for j = 1 : 256 for k = 1 : 3 myRand = rand/2-0.25; I2(i,j,k) = I(i,j,k) + myRand * double(I(i,j,k)); endfor endfor endfor clear i, j, k Idiff = uint8(abs(double(I2) - double(I))); numSame = 0; for i = 1 : 256 for j = 1 : 256 if (Idiff(i,j,1)==0 && Idiff(i,j,2)==0 && Idiff(i,j,3)==0) numSame = numSame + 1; endif endfor endfor H = (1/25) * ones(5); I2AVGfiltRed = imfilter(I2(:,:,1), H); I2AVGfiltGreen = imfilter(I2(:,:,2), H); I2AVGfiltBlue = imfilter(I2(:,:,3), H); I3 = uint8(zeros(256,256,3)); I3(:,:,1) = I2AVGfiltRed; I3(:,:,2) = I2AVGfiltGreen; I3(:,:,3) = I2AVGfiltBlue; I2MEDfiltRed = ordfilt2(I2(:,:,1), 13, ones(5)); I2MEDfiltGreen = ordfilt2(I2(:,:,2), 13, ones(5)); I2MEDfiltBlue = ordfilt2(I2(:,:,3), 13, ones(5)); I4 = uint8(zeros(256,256,3)); I4(:,:,1) = I2MEDfiltRed; I4(:,:,2) = I2MEDfiltGreen; I4(:,:,3) = I2MEDfiltBlue; psnrAVG = psnr(I3, I2, 255); psnrMED = psnr(I4, I2, 255); subplot(2,3,1), imshow(I,[0 255]), title('Original') subplot(2,3,2), imshow(I2,[0 255]), title('Randomized') subplot(2,3,3), imshow(Idiff,[]), title('Difference image') subplot(2,3,4), imshow(I3,[0 255]), title('AVG filtered') subplot(2,3,5), imshow(I4,[0 255]), title('MED filtered')