# Compare the wavelet based progressive coding methods SPIHT and EZW

## Encode by SPIHT with a varying parameter "maxloop" (indicating how many binary planes are used)

```X = imread('wpeppers.jpg');
for ij = 1:14
[cr(ij),bpp(ij)] = wcompress('c',X,'wpeppers.wtc','spiht','maxloop',ij);
Xc = wcompress('u','wpeppers.wtc');
delete('wpeppers.wtc')
D = abs(double(X)-double(Xc)).^2;
mse  = sum(D(:))/numel(X);
psnr(ij) = 10*log10(255*255/mse);
figure(1),clf, subplot(1,2,1); image(X);  title('Original image'), axis square
subplot(1,2,2); image(Xc); title(['BPP =  ' num2str(bpp(ij)) ' PSNR = ' num2str(psnr(ij))])
axis square
PSNR_BPP = [psnr(ij) bpp(ij)]
%pause
end
```
```PSNR_BPP =

8.0081    0.0021

PSNR_BPP =

11.0868    0.0022

PSNR_BPP =

13.6291    0.0020

PSNR_BPP =

14.5624    0.0022

PSNR_BPP =

15.9676    0.0027

PSNR_BPP =

17.3006    0.0042

PSNR_BPP =

19.5902    0.0084

PSNR_BPP =

21.8116    0.0175

PSNR_BPP =

24.5459    0.0399

PSNR_BPP =

27.4784    0.0899

PSNR_BPP =

30.5643    0.1929

PSNR_BPP =

33.8526    0.3966

PSNR_BPP =

37.1234    0.7678

PSNR_BPP =

40.4365    1.4560

```

## Encode by EZW with a varying parameter "maxloop" (indicating how many binary planes are used)

```for ij = 1:14
[cr2(ij),bpp2(ij)] = wcompress('c',X,'wpeppers.wtc','ezw','maxloop',ij);
Xc = wcompress('u','wpeppers.wtc');
delete('wpeppers.wtc')
D = abs(double(X)-double(Xc)).^2;
mse  = sum(D(:))/numel(X);
psnr2(ij) = 10*log10(255*255/mse);
figure(2),clf, subplot(1,2,1); image(X);  title('Original image'), axis square
subplot(1,2,2); image(Xc); title(['BPP =  ' num2str(bpp2(ij)) ' PSNR = ' num2str(psnr2(ij))])
axis square
PSNR_BPP = [psnr2(ij) bpp2(ij)]
%pause
end
```
```PSNR_BPP =

11.8967    0.0025

PSNR_BPP =

14.2211    0.0027

PSNR_BPP =

14.7222    0.0028

PSNR_BPP =

16.0449    0.0037

PSNR_BPP =

17.4743    0.0064

PSNR_BPP =

19.8797    0.0128

PSNR_BPP =

22.2389    0.0273

PSNR_BPP =

25.1090    0.0605

PSNR_BPP =

28.0965    0.1350

PSNR_BPP =

31.3082    0.2937

PSNR_BPP =

34.6667    0.6023

PSNR_BPP =

37.9678    1.1807

PSNR_BPP =

41.2355    2.2426

PSNR_BPP =

44.2792    4.1570

```

## Plot the rate-PSNR curves comparing the two algorithms

```figure(2),clf
plot(bpp,psnr,'or-')
hold on
plot(bpp2(1:length(psnr2)),psnr2,'bo-')
xlabel('BIT RATE [bpp]')
ylabel('PSNR [dB]')
legend('SPIHT','EZW','Location','northwest')
grid
```