The Lifting Scheme of Reverse Order High Golden Section Transform By Matlab Part I

This is the lifting scheme of 2d Reverse Order high golden section transform matlab codes:

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function H = rhgst2d(X,nlevel)
 
% Author: Jun Li. Copyright (c) 2015, All rights reserved. 
% more info@ http://goldensectiontransform.com/
% the lifting scheme of 2d reverse order high golden section transform
% here matrix X is of Fn*Fn where Fn is a fibonacci number Fn>=2.
 
global hj; % only used by function rhgst1d(S) below.
global FBH; % only used by function rhgst1d(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] = rhgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = rhgst1d(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 reverse order high golden section transform lifting scheme
 
function [ss,dd] = rhgst1d(S)
 
%% Author: Jun Li. more info@ http://goldensectiontransform.com/
 
global hj;
global FBH;
 
index = 0;
g = 1;
h = 1;
 
rhform = fliplr(hword(length(S))); % [2 3 3 2 3] -> [3 2 3 3 2]
 
for i=1:length(rhform)
 
   index = index + rhform(i);
 
   if rhform(i) == 2
 
      % ss(i) = (sqrt(FBH(2*hj))*S(index-1)+sqrt(FBH(2*hj-1))*S(index))/sqrt(FBH(2*hj+1));
      % dd(2*i-g) = (sqrt(FBH(2*hj-1))*S(index-1)-sqrt(FBH(2*hj))*S(index))/sqrt(FBH(2*hj+1));
 
      %% we can use lifting scheme here:
 
      ga = sqrt(FBH(2*hj)/FBH(2*hj-1));
      gb = sqrt(FBH(2*hj)*FBH(2*hj-1))/FBH(2*hj+1);
      gc = sqrt(FBH(2*hj+1)/FBH(2*hj-1));
 
      d1 = S(index-1) - ga*S(index);
      s1 = S(index) + gb*d1;
      ss(i) = gc*s1;
      dd(2*i-g) = d1/gc;
 
      g = g+1;
 
   else % rhform(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);
 
      %% we can use lifting scheme here:
 
      td1 = S(index-2) - S(index);
      ts1 = S(index) + 1/2*td1;
      tss = sqrt(2)*ts1;
      tdd = td1/sqrt(2);
 
      ha = sqrt(2*FBH(2*hj)/FBH(2*hj-1));
      hb = sqrt(2*FBH(2*hj-1)*FBH(2*hj))/FBH(2*hj+2);
      hc = sqrt(FBH(2*hj+2)/FBH(2*hj-1));
 
      td2 = tss - ha*S(index-1);
      ts2 = S(index-1) + hb*td2;
      ss(i) = hc*ts2;
      dd(i+h-1) = td2/hc;
      dd(i+h) = tdd;
 
      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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
function X = irhgst2d(H,nlevel)
 
% Author: Jun Li. Copyright (c) 2015, All rights reserved. 
% more info@ http://goldensectiontransform.com/
% the lifting scheme of inverse 2d reverse order high golden section transform
% here matrix H is of Fn*Fn where Fn is a fibonacci number Fn>=2.
 
global hji; % only used by function irhgst1d(S) below.
global FBHI; % only used by function irhgst1d(S) below.
 
[xx,yy] = size(H);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBHI = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBHI = Fibonacci sequence -> [1 1 2 3 5 8...];
 
X=H;
for hji=nlevel:-1:1
 
   for j=1:FBHI(end-2*hji+2)
      ss = X(1:FBHI(end-2*hji),j);
      dd = X(FBHI(end-2*hji)+1:FBHI(end-2*hji+2),j);
      X(1:FBHI(end-2*hji+2),j) = irhgst1d(ss',dd')'; % inverse column transform
   end
 
   for k=1:FBHI(end-2*hji+2)
      ss = X(k,1:FBHI(end-2*hji));
      dd = X(k,FBHI(end-2*hji)+1:FBHI(end-2*hji+2));
      X(k,1:FBHI(end-2*hji+2)) = irhgst1d(ss,dd); % inverse row transform
   end
 
end
 
 
%% inverse 1d reverse order high golden section transform lifting scheme
 
function S = irhgst1d(ss,dd)
 
%% Author: Jun Li. more info@ http://goldensectiontransform.com/
 
global hji;
global FBHI;
 
N = length(ss) + length(dd);
index = 0;
g = 1;
h = 1;
 
rhform = fliplr(hword(N)); % [2 3 3 2 3] -> [3 2 3 3 2]
 
for i=1:length(rhform)
 
   index = index + rhform(i);
 
   if rhform(i) == 2
 
      % S(index-1) = (sqrt(FBHI(2*hji))*ss(i)+sqrt(FBHI(2*hji-1))*dd(2*i-g))/sqrt(FBHI(2*hji+1));
      % S(index) = (sqrt(FBHI(2*hji-1))*ss(i)-sqrt(FBHI(2*hji))*dd(2*i-g))/sqrt(FBHI(2*hji+1));
 
      %% we can use lifting scheme here:
 
      ga = sqrt(FBHI(2*hji)/FBHI(2*hji-1));
      gb = sqrt(FBHI(2*hji)*FBHI(2*hji-1))/FBHI(2*hji+1);
      gc = sqrt(FBHI(2*hji+1)/FBHI(2*hji-1));
 
      d1 = gc*dd(2*i-g);
      s1 = ss(i)/gc;
      S(index) = s1 - gb*d1;
      S(index-1) = d1 + ga*S(index);
 
      g = g+1;
 
   else % rhform(i) == 3
 
      % S(index-2) = (sqrt(FBHI(2*hji))*ss(i)+sqrt(FBHI(2*hji-1)/2)*dd(i+h-1))/sqrt(FBHI(2*hji+2))+dd(i+h)/sqrt(2);
      % S(index-1) = (sqrt(FBHI(2*hji-1))*ss(i)-sqrt(2*FBHI(2*hji))*dd(i+h-1))/sqrt(FBHI(2*hji+2));
      % S(index) = (sqrt(FBHI(2*hji))*ss(i)+sqrt(FBHI(2*hji-1)/2)*dd(i+h-1))/sqrt(FBHI(2*hji+2))-dd(i+h)/sqrt(2);
 
      %% we can use lifting scheme here:
 
      ha = sqrt(2*FBHI(2*hji)/FBHI(2*hji-1));
      hb = sqrt(2*FBHI(2*hji-1)*FBHI(2*hji))/FBHI(2*hji+2);
      hc = sqrt(FBHI(2*hji+2)/FBHI(2*hji-1));
 
      tdd = dd(i+h);
      td2 = hc*dd(i+h-1);
      ts2 = ss(i)/hc;
      S(index-1) = ts2 - hb*td2;
      tss = td2 + ha*S(index-1);
 
      td1 = sqrt(2)*tdd;
      ts1 = tss/sqrt(2);
      S(index) = ts1 - 1/2*td1;
      S(index-2) = td1 + S(index);
 
      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
25
26
27
 
function hform = hword(n)
 
% Author: Jun Li. Copyright (c) 2015, All rights reserved. 
% more info@ http://goldensectiontransform.com/
% 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

we can use wythoff sequence here

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function H = rhgst2d(X,nlevel)
 
% Author: Jun Li. Copyright (c) 2015, All rights reserved. 
% more info@ http://goldensectiontransform.com/
% the lifting scheme of 2d reverse order high golden section transform
% here matrix X is of Fn*Fn where Fn is a fibonacci number Fn>=2.
% Wythoff sequence is used here, no need to call function_hword.
 
global hj; % only used by function rhgst1d(S) below.
global FBH; % only used by function rhgst1d(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] = rhgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = rhgst1d(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 reverse order high golden section transform lifting scheme
 
function [ss,dd] = rhgst1d(S)
 
%% Author: Jun Li. more info@ http://goldensectiontransform.com/
 
global hj;
global FBH;
 
if length(S) == 2
 
   % ss(1) = (sqrt(FBH(2*hj))*S(1)+sqrt(FBH(2*hj-1))*S(2))/sqrt(FBH(2*hj+1));
   % dd(1) = (sqrt(FBH(2*hj-1))*S(1)-sqrt(FBH(2*hj))*S(2))/sqrt(FBH(2*hj+1));
 
   %% we can use lifting scheme here:
 
   ga = sqrt(FBH(2*hj)/FBH(2*hj-1));
   gb = sqrt(FBH(2*hj)*FBH(2*hj-1))/FBH(2*hj+1);
   gc = sqrt(FBH(2*hj+1)/FBH(2*hj-1));
 
   d1 = S(1) - ga*S(2);
   s1 = S(2) + gb*d1;
   ss(1) = gc*s1;
   dd(1) = d1/gc;
 
else %length(S) == 3,5,8,13,21...
 
   for i=1:FBH(end-2*hj-1)
 
      lw = floor((1+sqrt(5))/2*i); % Lower Wythoff sequence->1,3,4,6,8...
      % uw = floor((3+sqrt(5))/2*i); % Upper Wythoff sequence->2,5,7,10,13...
      uw = lw + i;
 
      % ss(lw) = (sqrt(FBH(2*hj))*S(lw+uw-2)+sqrt(FBH(2*hj-1))*S(lw+uw-1)+sqrt(FBH(2*hj))*S(lw+uw))/sqrt(FBH(2*hj+2));
      % dd(uw-1) = (sqrt(FBH(2*hj-1))*S(lw+uw-2)-2*sqrt(FBH(2*hj))*S(lw+uw-1)+sqrt(FBH(2*hj-1))*S(lw+uw))/sqrt(2*FBH(2*hj+2));
      % dd(uw) = (S(lw+uw-2)-S(lw+uw))/sqrt(2);
 
      %% we can use lifting scheme here:
 
      td1 = S(lw+uw-2) - S(lw+uw);
      ts1 = S(lw+uw) + 1/2*td1;
      tss = sqrt(2)*ts1;
      tdd = td1/sqrt(2);
 
      ha = sqrt(2*FBH(2*hj)/FBH(2*hj-1));
      hb = sqrt(2*FBH(2*hj-1)*FBH(2*hj))/FBH(2*hj+2);
      hc = sqrt(FBH(2*hj+2)/FBH(2*hj-1));
 
      td2 = tss - ha*S(lw+uw-1);
      ts2 = S(lw+uw-1) + hb*td2;
      ss(lw) = hc*ts2;
      dd(uw-1) = td2/hc;
      dd(uw) = tdd;
 
      if (FBH(end-2*hj) ~= 1) & (i <= FBH(end-2*hj-2))
 
         % ss(uw) = (sqrt(FBH(2*hj))*S(2*uw+lw-1)+sqrt(FBH(2*hj-1))*S(2*uw+lw))/sqrt(FBH(2*hj+1));
         % dd(lw+uw) = (sqrt(FBH(2*hj-1))*S(2*uw+lw-1)-sqrt(FBH(2*hj))*S(2*uw+lw))/sqrt(FBH(2*hj+1));
 
         %% we can use lifting scheme here:
 
         ga = sqrt(FBH(2*hj)/FBH(2*hj-1));
         gb = sqrt(FBH(2*hj)*FBH(2*hj-1))/FBH(2*hj+1);
         gc = sqrt(FBH(2*hj+1)/FBH(2*hj-1));
 
         d1 = S(2*uw+lw-1) - ga*S(2*uw+lw);
         s1 = S(2*uw+lw) + gb*d1;
         ss(uw) = gc*s1;
         dd(lw+uw) = d1/gc;
 
      end
 
   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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function X = irhgst2d(H,nlevel)
 
% Author: Jun Li. Copyright (c) 2015, All rights reserved. 
% more info@ http://goldensectiontransform.com/
% the lifting scheme of inverse 2d reverse order high golden section transform
% here matrix H is of Fn*Fn where Fn is a fibonacci number Fn>=2.
% Wythoff sequence is used here, no need to call function_hword.
 
global hji; % only used by function irhgst1d(S) below.
global FBHI; % only used by function irhgst1d(S) below.
 
[xx,yy] = size(H);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBHI = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBHI = Fibonacci sequence -> [1 1 2 3 5 8...];
 
X=H;
for hji=nlevel:-1:1
 
   for j=1:FBHI(end-2*hji+2)
      ss = X(1:FBHI(end-2*hji),j);
      dd = X(FBHI(end-2*hji)+1:FBHI(end-2*hji+2),j);
      X(1:FBHI(end-2*hji+2),j) = irhgst1d(ss',dd')'; % inverse column transform
   end
 
   for k=1:FBHI(end-2*hji+2)
      ss = X(k,1:FBHI(end-2*hji));
      dd = X(k,FBHI(end-2*hji)+1:FBHI(end-2*hji+2));
      X(k,1:FBHI(end-2*hji+2)) = irhgst1d(ss,dd); % inverse row transform
   end
 
end
 
 
%% inverse 1d reverse order high golden section transform lifting scheme
 
function S = irhgst1d(ss,dd)
 
%% Author: Jun Li. more info@ http://goldensectiontransform.com/
 
global hji;
global FBHI;
 
if (length(ss)+length(dd)) == 2
 
   % S(1) = (sqrt(FBHI(2*hji))*ss(1)+sqrt(FBHI(2*hji-1))*dd(1))/sqrt(FBHI(2*hji+1));
   % S(2) = (sqrt(FBHI(2*hji-1))*ss(1)-sqrt(FBHI(2*hji))*dd(1))/sqrt(FBHI(2*hji+1));
 
   %% we can use lifting scheme here:
 
   ga = sqrt(FBHI(2*hji)/FBHI(2*hji-1));
   gb = sqrt(FBHI(2*hji)*FBHI(2*hji-1))/FBHI(2*hji+1);
   gc = sqrt(FBHI(2*hji+1)/FBHI(2*hji-1));
 
   d1 = gc*dd(1);
   s1 = ss(1)/gc;
   S(2) = s1 - gb*d1;
   S(1) = d1 + ga*S(2);
 
 
else % (length(ss)+length(dd)) == 3,5,8,13,21...
 
   for i=1:FBHI(end-2*hji-1)
 
      lw = floor((1+sqrt(5))/2*i); % Lower Wythoff sequence->1,3,4,6,8...
      % uw = floor((3+sqrt(5))/2*i); % Upper Wythoff sequence->2,5,7,10,13...
      uw = lw + i;
 
      % S(lw+uw-2) = sqrt(FBHI(2*hji))/sqrt(FBHI(2*hji+2))*ss(lw)+sqrt(FBHI(2*hji-1))/sqrt(2*FBHI(2*hji+2))*dd(uw-1)+dd(uw)/sqrt(2);
      % S(lw+uw-1) = (sqrt(FBHI(2*hji-1))*ss(lw)-sqrt(2*FBHI(2*hji))*dd(uw-1))/sqrt(FBHI(2*hji+2));
      % S(lw+uw) = sqrt(FBHI(2*hji))/sqrt(FBHI(2*hji+2))*ss(lw)+sqrt(FBHI(2*hji-1))/sqrt(2*FBHI(2*hji+2))*dd(uw-1)-dd(uw)/sqrt(2);
 
      %% we can use lifting scheme here:
 
      ha = sqrt(2*FBHI(2*hji)/FBHI(2*hji-1));
      hb = sqrt(2*FBHI(2*hji-1)*FBHI(2*hji))/FBHI(2*hji+2);
      hc = sqrt(FBHI(2*hji+2)/FBHI(2*hji-1));
 
      tdd = dd(uw);
      td2 = hc*dd(uw-1);
      ts2 = ss(lw)/hc;
      S(lw+uw-1) = ts2 - hb*td2;
      tss = td2 + ha*S(lw+uw-1);
 
      td1 = sqrt(2)*tdd;
      ts1 = tss/sqrt(2);
      S(lw+uw) = ts1 - 1/2*td1;
      S(lw+uw-2) = td1 + S(lw+uw);
 
      if (FBHI(end-2*hji) ~= 1) & (i <= FBHI(end-2*hji-2))
 
         % S(2*uw+lw-1) = (sqrt(FBHI(2*hji))*ss(uw)+sqrt(FBHI(2*hji-1))*dd(lw+uw))/sqrt(FBHI(2*hji+1));
         % S(2*uw+lw) = (sqrt(FBHI(2*hji-1))*ss(uw)-sqrt(FBHI(2*hji))*dd(lw+uw))/sqrt(FBHI(2*hji+1));
 
         %% we can use lifting scheme here:
 
         ga = sqrt(FBHI(2*hji)/FBHI(2*hji-1));
         gb = sqrt(FBHI(2*hji)*FBHI(2*hji-1))/FBHI(2*hji+1);
         gc = sqrt(FBHI(2*hji+1)/FBHI(2*hji-1));
 
         d1 = gc*dd(lw+uw);
         s1 = ss(uw)/gc;
         S(2*uw+lw) = s1 - gb*d1;
         S(2*uw+lw-1) = d1 + ga*S(2*uw+lw);
 
      end
 
   end
 
end

download pdf

download from https://github.com/jasonli30s

Leave a Reply

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