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

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

Summary of programs:

1. testlgstfn.m – main file: lgst of Lena 377*377
2. lgst2d.m – forward 2d low golden section transform
3. ilgst2d.m – inverse 2d low golden section transform
4. lword.m – Type-L golden section decomposion of fibonacci number

download zip

Results:

Leave a Reply

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