0% found this document useful (0 votes)
28 views

Image Compression Documentation: Code

This document discusses image compression techniques using discrete cosine transform (DCT), fast Fourier transform (FFT), and singular value decomposition (SVD). It provides code to apply these techniques to compress an image, and calculates the mean squared error (MSE), peak signal-to-noise ratio (PSNR), and compression ratio (CR) for different threshold values. Observations are recorded for DCT, FFT, and SVD compression trials by varying the threshold and keeping other parameters constant.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Image Compression Documentation: Code

This document discusses image compression techniques using discrete cosine transform (DCT), fast Fourier transform (FFT), and singular value decomposition (SVD). It provides code to apply these techniques to compress an image, and calculates the mean squared error (MSE), peak signal-to-noise ratio (PSNR), and compression ratio (CR) for different threshold values. Observations are recorded for DCT, FFT, and SVD compression trials by varying the threshold and keeping other parameters constant.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Image Compression Documentation

WAP applying DCT, FFT, and DCT and also, find the MSE, PSNR, and CR.

CODE:
clc;
clear all;
a=imread('cameraman.tif');
b=dct2(a);
b(abs(b)<100)=0;
c=fft2(b);
d=dct2(c);
id=idct2(d);
ic=ifft2(c);
ib=idct2(b);
square=(double(a)-double(ib))^2;
[mrows mcol]=size(a);
mse=sum(sum(square))/mrows*mcol
psnr=10*log(256^2/mse)
x=numel(find(b));
cr=(mrows*mcol)/x
figure(1)
imshow(a);
figure(2);
ib=uint8(ib);
imshow(ib);
OBSERVATIONS:
Trial
No

1.

Original
Image

Thres
hold
Value
30

Reconstructed
Image

MSE,
PSNR,
and
CR.
mse =

-8.4443
e+005

psnr =

-25.560
6
+31.41

59i

cr =

2.

100

8.7615
mse =

2.2572
e+006

psnr =

-35.393
0

cr =

3.

250

55.918
1
mse =

-1.8111
e+006

psnr =

-33.190
8
+31.41
59i

cr =

243.62
83

4.

500

mse =

4.5238
e+006

psnr =

-42.345
0

cr =

5.

1000

819.20
00
mse =

4.4099
e+007

psnr =

-65.115
8

cr =

3.2768
e+003

WAP applying fft2 and fft2 and also, find the MSE , PSNR, and CR.
CODE:
clc;
clear all;
a=imread('cameraman.tif');
b=fft2(a);
b(abs(b)<500000)=0;
c=fft2(b);

d=ifft2(c);
e=ifft2(d);
square=(double(a)-double(e))^2;
[mrows mcol]=size(a);
mse=sum(sum(square))/mrows*mcol
psnr=10*log(256^2/mse)
x=numel(find(b));
cr=(mrows*mcol)/x
figure(1)
imshow(a);
figure(2)
e=uint8(e);
imshow(e);
OBSERVATIONS:
Tria
l No

1.

Original
Image

Thres
hold
Value
5000

Reconstructed
Image

MSE,
PSNR,
and
CR.
mse =

-1.2852
e+005
+1.315
0e-009i

psnr =

-6.7347
-31.415
9i

cr =

2.

4.5508
mse =

4.8726
e+005
+3.861
4e-009i

psnr =

-20.061
90.0000i

cr =

12.018
3
3.

20,00
0

mse =

8.4662
e+006
+2.585
4e-008i

psnr =

-48.612
30.0000i

cr =

4.

50000

33.974
1
mse =

8.8932
e+006
+9.175
8e-010i

psnr =

-49.104
50.0000i

cr =

5.

10000
0

152.76
46
mse =

7.0318
e+007
-2.4677
e-008i

psnr =

-69.781
9+
0.0000i

cr =

6.

50000
0

524.28
80
mse =

6.3336
e+008
+2.753
1e-009i

psnr =

-91.761
90.0000i

cr =

5.0412
e+003

WAP applying SVD, and also find MSE, PSNR, and CR.

CODE:
clc;
clear all;
a=imread('cameraman.tif');
[u s v]=svd(double(a));
u(abs(u)<0.0001)=0;
s(abs(s)<70)=0;
v(abs(v)<0.1)=0;

r=u*s*v';

square=(double(a)-double(r))^2;
[mrows mcol]=size(a);
mse=sum(sum(square))/(mrows*mcol)
psnr=10*log(255^2/mse)
x=numel(find(a));
cr=(mrows*mcol)/x
figure(1)

imshow(a);

figure(2);
r=uint8(r);
imshow(r);

Observations :
Keeping S and V constant :
Tri
al
1.

Original Image

Threshold
Values for U
0.01

Reconstructed
Image

MSE and
PSNR
mse =

1.0518
psnr =
2.

0.05

110.3200
mse =

4.0411e
+004
psnr =
3.

0.08

4.7567
mse =

2.1160e
+006
psnr =
-34.8253

4.

0.1

mse =

3.5611e
+006
psnr =
5.

0.15

-40.0305
mse =

3.5675e
+006
psnr =
-40.0485
Keeping U and V constant.
Trial

1.

Original
Image

Threshol
d values
for S
500

Reconstructed Image

MSE and
PSNR
mse =

0.0294
psnr =
146.0867
2.

1000

mse =

0.2553
psnr =
124.4796

3.

5000

mse =

2.6085
psnr =
101.2374

Keeping U and S constant and varying V


Trial

1.

Origina
l
Image

Threshol
d value
for V
0.05

Reconstructed Image

MSE and PSNR

mse =

2.2607e+0
05
psnr =
-12.4609
2.

0.1

mse =

3.6128e+0
06
psnr =
-40.1747
3.

0.15

mse =

3.5640e+0
06
psnr =
-40.0386

You might also like