-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzigzag_e.m
109 lines (90 loc) · 3.33 KB
/
zigzag_e.m
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
%=================================================================================
% Advanced Multimedia Applications
% Title : ZigZag Encoder (zigzag_e.m)
% Description : Zig-zag encoder for matrixs
% usage => optdata = zigzag_e(inpdata);
% The function scans the input data(inpdata) in zig-zag format and
% returns it as a matrix of same dimention
%
% Input : (matrix)
% Outout : Inverse-Zigzag (matrix)
%=================================================================================
function [zig_data] = zigzag_e(idata)
%%
%% Zig-zag encoder for matrixs
%%
%%
%% usage => optdata = zigzag_e(inpdata);
%%
%% The function scans the input data(inpdata) in zig-zag format and returns
%% it as a matrix of same dimention
%%
[xlen,ylen] = size(idata); % getting size of matrix
if xlen ~= ylen % checking for square matrix
disp(' ');
disp('Zig-Zag encoder ERROR : Square matrix needed as input.');
disp(' ');
return;
end;
count = 1; x = 1; y = 1; % initalising counter variables
zig_data = zeros(xlen , ylen); % initialising output matrix
zig_data(1,1) = idata(1,1);
% Top half ---------------
while (1)
y=y+1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
while(y~=1) % to loop till reaching the top edge(for moving diagonally up)
x=x+1;
y=y-1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
end
x=x+1;
if(x>xlen) % to detect the end of top half
x=x-1;
break;
end;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
while(x~=1) % to loop till reaching the left edge(for moving diagonally down)
x=x-1;
y=y+1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
end;
end;
% bottom half -----------
while(1)
y=y+1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
% to loop till reaching the bottom edge(for moving diagonally down)
while(y~=ylen)
y=y+1;
x=x-1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
end;
x=x+1;
if(x>xlen) % to detect end of bottom half
x=x-1;
break;
end;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
while(x~=xlen) % to loop till reaching the right edge(for moving diagonally up)
x=x+1;
y=y-1;
count = count + 1; % data logger
zig_data(fix(((count-1)/xlen)+1),count-((fix((count-1)/xlen)*xlen))) =...
idata(x,y);
end;
end;