Simple Image Compression Comparison Using Golden Section Transform, Haar Wavelet Transform and Daubechies D4 Wavelet By Matlab

Introduction:
In mathematics, Golden Section Transform is a new class of discrete orthogonal transform. Its theory involves golden ratio, Fibonacci number, Fourier analysis, wavelet theory, stochastic process, integer partition, matrix analysis, group theory, combinatorics on words, its applied fields include digital signal (image/audio/video) processing, denoising, watermarking, compression, coding and so on.

Simple Compression Scheme:
1. Source image is divided into 8 × 8 blocks of pixels
2. Apply 2D transform (LGST, HGST, Haar, D4) to each 8 × 8 block
3. Set compression ratio, keep largest abs(elements) in each block, and set all the others to zero
4. Apply inverse 2D transform to each 8 × 8 block to reconstruct the image
5. Compute PSNR and compare the results.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function H = lgst2d(X)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
%
% function H = lgst2d(X,nlevel)
% 4-level 2d low golden section transform of 8*8 image matrix
 
nlevel = 4; % 4-level transform for each 8*8 image block
 
global lj; % only used by function lgst1d(S) below.
global FBL; % only used by function lgst1d(S) below.
 
[xx,yy] = size(X);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBL = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBL = Fibonacci sequence -> [1 1 2 3 5 8...];
 
H=X;
for lj=1:nlevel
 
   for j=1:xx
      [ss,dd] = lgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = lgst1d(H(1:xx,k)'); % column transform
      H(1:xx,k) = [ss,dd]';
   end
 
   xx = FBL(end-lj); % round((sqrt(5)-1)/2*xx); 8*8 block: xx=8->5->3->2
   yy = FBL(end-lj); % round((sqrt(5)-1)/2*yy); 8*8 block: yy=8->5->3->2
 
end
 
%% 1d low golden section transform
 
function [ss,dd] = lgst1d(S)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global lj;
global FBL;
 
index = 0; 
h = 1;
 
lform = lword(length(S)); 
 
for i=1:length(lform)
 
   index = index + lform(i);
 
   if lform(i) == 1
 
      ss(i) = S(index);
 
   else % lform(i) == 2
 
      ss(i) = (sqrt(FBL(lj))*S(index-1)+sqrt(FBL(lj+1))*S(index))/sqrt(FBL(lj+2));
      dd(h) = (sqrt(FBL(lj+1))*S(index-1)-sqrt(FBL(lj))*S(index))/sqrt(FBL(lj+2));
      h = h+1;
 
   end
 
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function lform = lword(n)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% Type-L golden section decomposion of fibonacci number n, 
% e.g. lword(8) = [1 2 2 1 2];
 
 
if n == 1
 
   lform = [1];
 
elseif n == 2
 
   lform = [2];
 
 
else 
 
next = round((sqrt(5)-1)/2*n); 
 
lform = [lword(n-next),lword(next)];
 
 
end

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function H = hgst2d(X)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
%
% function H = hgst2d(X,nlevel)
% 2-level 2d high golden section transform of 8*8 image matrix
 
nlevel = 2; % 2-level transform for each 8*8 image block
 
global hj; % only used by function hgst1d(S) below.
global FBH; % only used by function hgst1d(S) below.
 
[xx,yy] = size(X);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBH = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBH = Fibonacci sequence -> [1 1 2 3 5 8...];
 
H=X;
for hj=1:nlevel
 
   for j=1:xx
      [ss,dd] = hgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = hgst1d(H(1:xx,k)'); % column transform
      H(1:xx,k) = [ss,dd]';
   end
 
   xx = FBH(end-2*hj); % round((3-sqrt(5))/2*xx); 8*8 block: xx=8->3
   yy = FBH(end-2*hj); % round((3-sqrt(5))/2*yy); 8*8 block: yy=8->3
 
end
 
%% 1d high golden section transform
 
function [ss,dd] = hgst1d(S)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global hj;
global FBH;
 
index = 0;
g = 1;
h = 1;
 
hform = hword(length(S)); 
 
for i=1:length(hform)
 
   index = index + hform(i);
 
   if hform(i) == 2
 
      ss(i) = (sqrt(FBH(2*hj-1))*S(index-1)+sqrt(FBH(2*hj))*S(index))/sqrt(FBH(2*hj+1));
      dd(2*i-g) = (sqrt(FBH(2*hj))*S(index-1)-sqrt(FBH(2*hj-1))*S(index))/sqrt(FBH(2*hj+1));
      g = g+1;
 
   else % hform(i) == 3
 
      ss(i) = (sqrt(FBH(2*hj))*S(index-2)+sqrt(FBH(2*hj-1))*S(index-1)+sqrt(FBH(2*hj))*S(index))/sqrt(FBH(2*hj+2));
      dd(i+h-1) = (sqrt(FBH(2*hj-1))*S(index-2)-2*sqrt(FBH(2*hj))*S(index-1)+sqrt(FBH(2*hj-1))*S(index))/sqrt(2*FBH(2*hj+2));
      dd(i+h) = (S(index-2)-S(index))/sqrt(2);
      h = h+1;
 
   end
 
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function hform = hword(n)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% Type-H golden section decomposion of fibonacci number n, 
% e.g. hword(8) = [3 2 3];
 
 
if n == 2
 
   hform = [2];
 
elseif n == 3
 
   hform = [3];
 
else 
 
next = round((sqrt(5)-1)/2*n); 
 
hform = [hword(n-next),hword(next)];
 
 
end

Results:







Leave a Reply

Your email address will not be published. Required fields are marked *