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

This is the lifting scheme of 2d reverse order low 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
function H = rlgst2d(X,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% the lifting scheme of 2d reverse order low golden section transform
% here matrix X is of Fn*Fn where Fn is a fibonacci number Fn>=2.
 
global lj; % only used by function rlgst1d(S) below.
global FBL; % only used by function rlgst1d(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] = rlgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = rlgst1d(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 reverse order low golden section transform lifting scheme
 
function [ss,dd] = rlgst1d(S)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global lj;
global FBL;
 
index = 0;
h = 1;
 
rlform = fliplr(lword(length(S))); % [1 2 2 1 2] -> [2 1 2 2 1]
 
for i=1:length(rlform)
 
   index = index + rlform(i);
 
   if rlform(i) == 1
 
      ss(i) = S(index);
 
   else % rlform(i) == 2
 
      % ss(i) = (sqrt(FBL(lj+1))*S(index-1)+sqrt(FBL(lj))*S(index))/sqrt(FBL(lj+2));
      % dd(h) = (sqrt(FBL(lj))*S(index-1)-sqrt(FBL(lj+1))*S(index))/sqrt(FBL(lj+2));
 
      %% we can use lifting scheme here:
 
      ga = sqrt(FBL(lj+1)/FBL(lj));
      gb = sqrt(FBL(lj)*FBL(lj+1))/FBL(lj+2);
      gc = sqrt(FBL(lj+2)/FBL(lj));
 
      d1 = S(index-1) - ga*S(index);
      s1 = S(index) + gb*d1;
      ss(i) = gc*s1;
      dd(h) = d1/gc;
 
      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
function X = irlgst2d(H,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% the lifting scheme of inverse 2d reverse order low golden section transform
% here matrix H is of Fn*Fn where Fn is a fibonacci number Fn>=2.
 
global lji; % only used by function irlgst1d(S) below.
global FBLI; % only used by function irlgst1d(S) below.
 
[xx,yy] = size(H);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBLI = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBLI = Fibonacci sequence -> [1 1 2 3 5 8...];
 
X=H;
for lji=nlevel:-1:1
 
   for j=1:FBLI(end-lji+1)
      ss = X(1:FBLI(end-lji),j);
      dd = X(FBLI(end-lji)+1:FBLI(end-lji+1),j);
      X(1:FBLI(end-lji+1),j) = irlgst1d(ss',dd')'; % inverse column transform
   end
 
   for k=1:FBLI(end-lji+1)
      ss = X(k,1:FBLI(end-lji));
      dd = X(k,FBLI(end-lji)+1:FBLI(end-lji+1));
      X(k,1:FBLI(end-lji+1)) = irlgst1d(ss,dd); % inverse row transform
   end
 
end
 
 
%% inverse 1d reverse order low golden section transform lifting scheme
 
function S = irlgst1d(ss,dd)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global lji;
global FBLI;
 
N = length(ss) + length(dd);
index = 0; 
h = 1;
 
rlform = fliplr(lword(N)); % [1 2 2 1 2] -> [2 1 2 2 1]
 
for i=1:length(rlform)
 
   index = index + rlform(i);
 
   if rlform(i) == 1
 
      S(index) = ss(i);
 
   else % rlform(i) == 2
 
      % S(index-1) = (sqrt(FBLI(lji+1))*ss(i)+sqrt(FBLI(lji))*dd(h))/sqrt(FBLI(lji+2));
      % S(index) = (sqrt(FBLI(lji))*ss(i)-sqrt(FBLI(lji+1))*dd(h))/sqrt(FBLI(lji+2));
 
      %% we can use lifting scheme here:
 
      ga = sqrt(FBLI(lji+1)/FBLI(lji));
      gb = sqrt(FBLI(lji)*FBLI(lji+1))/FBLI(lji+2);
      gc = sqrt(FBLI(lji+2)/FBLI(lji));
 
      d1 = gc*dd(h);
      s1 = ss(i)/gc;
      S(index) = s1 - gb*d1;
      S(index-1) = d1 + ga*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
function testrlgstfn
 
% load 8 bit lena of size 377*377
 
X = im2double(imread('C:\lena377.bmp'));
 
[xx,yy] = size(X);
 
nlevel = 1;
 
H = rlgst2d(X,nlevel);
 
imshow(H);
 
title([num2str(nlevel),'-level normalized reverse order low golden section transform of',' Lena ',num2str(xx),'*',num2str(yy)]);
 
% R = irlgst2d(H,nlevel);
 
% EQ = isequal(round(X*255),round(R*255)) % Perfect Reconstruction
 
imwrite(H,'rlgstlena377.png','png');

Wythoff sequence is used here, no need to call lword function:

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
function H = rlgst2d(X,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% the lifting scheme of 2d reverse order low 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_lword.
 
global lj; % only used by function rlgst1d(S) below.
global FBL; % only used by function rlgst1d(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] = rlgst1d(H(j,1:yy)); % row transform
      H(j,1:yy) = [ss,dd];
   end
 
   for k=1:yy
      [ss,dd] = rlgst1d(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 reverse order low golden section transform lifting scheme
 
function [ss,dd] = rlgst1d(S)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global lj;
global FBL;
 
for i=1:FBL(end-lj-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(FBL(lj+1))*S(uw-1)+sqrt(FBL(lj))*S(uw))/sqrt(FBL(lj+2));
   % dd(i) = (sqrt(FBL(lj))*S(uw-1)-sqrt(FBL(lj+1))*S(uw))/sqrt(FBL(lj+2));
 
   %% we can use lifting scheme here:
 
   ga = sqrt(FBL(lj+1)/FBL(lj));
   gb = sqrt(FBL(lj)*FBL(lj+1))/FBL(lj+2);
   gc = sqrt(FBL(lj+2)/FBL(lj));
 
   d1 = S(uw-1) - ga*S(uw);
   s1 = S(uw) + gb*d1;
   ss(lw) = gc*s1;
   dd(i) = d1/gc;
 
   if (FBL(end-lj) ~= 1) & (i <= FBL(end-lj-2))
 
      ss(uw) = S(lw+uw);
 
   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
function X = irlgst2d(H,nlevel)
 
% Author: Jun Li, more info@ http://goldensectiontransform.org/
% the lifting scheme of inverse 2d reverse order low 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_lword.
 
global lji; % only used by function irlgst1d(S) below.
global FBLI; % only used by function irlgst1d(S) below.
 
[xx,yy] = size(H);
 
ind = floor(log(xx*sqrt(5)+1/2)/log((sqrt(5)+1)/2)); % determine index
FBLI = filter(1,[1 -1 -1],[1 zeros(1,ind-1)]);
% FBLI = Fibonacci sequence -> [1 1 2 3 5 8...];
 
X=H;
for lji=nlevel:-1:1
 
   for j=1:FBLI(end-lji+1)
      ss = X(1:FBLI(end-lji),j);
      dd = X(FBLI(end-lji)+1:FBLI(end-lji+1),j);
      X(1:FBLI(end-lji+1),j) = irlgst1d(ss',dd')'; % inverse column transform
   end
 
   for k=1:FBLI(end-lji+1)
      ss = X(k,1:FBLI(end-lji));
      dd = X(k,FBLI(end-lji)+1:FBLI(end-lji+1));
      X(k,1:FBLI(end-lji+1)) = irlgst1d(ss,dd); % inverse row transform
   end
 
end
 
 
%% inverse 1d reverse order low golden section transform lifting scheme
 
function S = irlgst1d(ss,dd)
 
%% Author: Jun Li, more info@ http://goldensectiontransform.org/
 
global lji;
global FBLI;
 
for i=1:FBLI(end-lji-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(uw-1) = (sqrt(FBLI(lji+1))*ss(lw)+sqrt(FBLI(lji))*dd(i))/sqrt(FBLI(lji+2));
   % S(uw) = (sqrt(FBLI(lji))*ss(lw)-sqrt(FBLI(lji+1))*dd(i))/sqrt(FBLI(lji+2));
 
   %% we can use lifting scheme here:
 
   ga = sqrt(FBLI(lji+1)/FBLI(lji));
   gb = sqrt(FBLI(lji)*FBLI(lji+1))/FBLI(lji+2);
   gc = sqrt(FBLI(lji+2)/FBLI(lji));
 
   d1 = gc*dd(i);
   s1 = ss(lw)/gc;
   S(uw) = s1 - gb*d1;
   S(uw-1) = d1 + ga*S(uw);
 
   if (FBLI(end-lji) ~= 1) & (i <= FBLI(end-lji-2))
 
      S(lw+uw) = ss(uw);
 
   end
 
end

Summary of programs:

1. testrlgstfn.m – main file: 2d rlgst of Lena 377*377
2. rlgst2d.m – forward 2d reverse order low golden section transform
3. irlgst2d.m – inverse 2d reverse order low golden section transform
4. lword.m – Type-L golden section decomposion of fibonacci numbera
5. rlgst2d.m – forward 2d reverse order low golden section transform(using Wythoff sequence)
6. irlgst2d.m – inverse 2d reverse order low golden section transform(using Wythoff sequence)

download zip

Results:


Leave a Reply

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