100% found this document useful (1 vote)
248 views7 pages

Q 5

Write a MATLAB function block dct2.m which takes an N × N pixel image, divides it into 8 ×8 pixel blocks (you may assume that N is divisible by 8), and returns the discrete cosine transform coefficients for each block. You will find the MATLAB command dct2.m helpful. Write another MATLAB function iblock dct2.m which is the inverse of the above: that takes the blocked DCT coefficients and returns the image.

Uploaded by

MaryamRazzaq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
248 views7 pages

Q 5

Write a MATLAB function block dct2.m which takes an N × N pixel image, divides it into 8 ×8 pixel blocks (you may assume that N is divisible by 8), and returns the discrete cosine transform coefficients for each block. You will find the MATLAB command dct2.m helpful. Write another MATLAB function iblock dct2.m which is the inverse of the above: that takes the blocked DCT coefficients and returns the image.

Uploaded by

MaryamRazzaq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question no 5

Part 1
a-

Output:

b-
Output
Part b

Output

Part c
for M=1

100

200

300

400

500

600

700

800

900

1000 for M=3


100 200 300 400 500 600 700 800 900 1000
100

200

300

400

500

600

700

800

900

1000
100 200 300 400 500 600 700 800 900 1000

for M=8

100

200

300

400

500

600

700

800

900

1000
100 200 300 400 500 600 700 800 900 1000
Part d
Code

x=double(imread('man.tiff'));
Block=block_dct2(x);
[m, n, nob]=size(Block);
s=n;
k=0;
noz=0; %number of zeros
nzn=0; %number of non zeros
for i=1:nob
quan(:,:,i)=Q.*round(Block(:,:,i)./Q); %quantized blocks
end
xq=iblock_dct2(quan);
b=x-xq; c=(norm(b,'fro')).^2; e=(norm(x,'fro')).^2;
disp('log10(||x-xq||^2/||x||=')
error=log10(c/e)
for i=1:(sqrt(nob*64)/s)
for j=1:(sqrt(nob*64)/s)
a((s*(i-1)+1:s*(i-1)+s),(s*(j-1)+1:s*(j-
1)+s))=Block(:,:,k+j); %dct coefficients matrix
qu((s*(i-1)+1:s*(i-1)+s),(s*(j-1)+1:s*(j-
1)+s))=quan(:,:,k+j); %quantized cofficients matrix
end
k=k+(sqrt(nob*64)/s);
end

disp('||a~ - a||');
A=norm((a-qu),'fro')
disp('||x~-x||');
B=norm(b,'fro')
%checking number of non-zero coefficients
[m,n]=size(qu);
for i=1:m
for j=1:m
if qu(i,j)==0
noz=noz+1;
else
nzn=nzn+1;
end
end
end
disp('number of non-zeros number');
a=nzn
imagesc(xq)
OUTPUT

quantized image

100

200

300

400

500

600

700

800

900

1000
100 200 300 400 500 600 700 800 900 1000

You might also like