DIP LAB8
S ABIRAMI
21BEC1464
clc
clear all;
close all;
a=imread("C:\Users\dsplab\Downloads\libraRRY.jpeg");
figure(1)
imshow(a)
title('original image');
[m,n]=size(a);
bs=8;
Rec_a=zeros(size(a));
for m1=1:1:8
for i=1:bs:(m-bs+1)
for j=1:bs:(n-bs+1)
block=a(i:i+bs-1,j:j+bs-1);
block_D=dct2(block);
d=zeros(size(block_D));
d(1:m1,1:m1)=block_D(1:m1,1:m1);
Rec_a(i:i+bs-1,j:j+bs-1)=idct2(d);
end
end
figure,imshow(uint8(Rec_a))
title('Reconstructed Image');
MSE=sum(sum((uint8(a)-uint8(Rec_a)).^2))/(m*n)
end
%high pass filtering to colour images
clc;
close all;
clear all;
a=imread("C:\Users\dsplab\Downloads\makeupp.jpeg");
yiq=rgb2ntsc(a);
b1=yiq(:,:,1);
h=[-1 -1 -1;-1 8 -1;-1 -1 -1];
c1=conv2(b1,h,'same');
yiq(:,:,1)=c1;
a1=ntsc2rgb(yiq);
figure, imshow(a),title('original image')
figure,imshow(a1),title('High pass filtered image')
%high pass filtering to colour images
clc;
close all;
clear all;
a=imread("C:\Users\dsplab\Downloads\makeupp.jpeg");
yiq=rgb2ntsc(a);
yiq_lp=yiq
b1=yiq(:,:,1);
h=[-1 -1 -1;-1 8 -1;-1 -1 -1];
h_lp=[1/9,1/9,1/9;1/9,1/9,1/9;1/9,1/9,1/9];
c1=conv2(b1,h,'same');
c1_lp=conv2(b1,h_lp,'same');
yiq(:,:,1)=c1;
yiq_lp(:,:,1)=c1_lp;
a1=ntsc2rgb(yiq);
a2=ntsc2rgb(yiq_lp);
figure, imshow(a),title('original image')
figure,imshow(a1),title('High pass filtered image')
figure,imshow(a2),title('Low pass filtered image')
clc
clear all
close all
a=imread("C:\Users\dsplab\Downloads\racecar.jpeg");
b=imnoise(a,'salt & pepper', 0.2);
c(:,:,1)=medfilt2(b(:,:,1));
c(:,:,2)=medfilt2(b(:,:,2));
c(:,:,3)=medfilt2(b(:,:,3));
imshow(a),title('original image')
figure,imshow(b),title('corrupted image')
figure,imshow(c),title('median filtered image')