-
Notifications
You must be signed in to change notification settings - Fork 0
/
findfeatures.m
125 lines (112 loc) · 3.19 KB
/
findfeatures.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function [result] = findfeatures(filename,dctlength)
%--------------------------------------------------------------------
%
% function [result] = findfeatures(filename,dctlength)
% filename: example 's1.pgm'
% dctlength: length of desired dct
% example: [result]=findfeatures('s1.pgm',35);
%
%--------------------------------------------------------------------
% Read image
[ingresso]=imread(filename);
Lout = dctlength;
% Do zig-zag scanning
[dimx,dimy] = size(ingresso);
dimprod = dimx*dimy;
zigzag = zeros(dimx,dimy);
ii = 1;
jj = 1;
zigzag(ii,jj) = 1;
slittox = 0;
slittoy = 1;
last = 0;
cont = 2;
% start and loop until cont becomes greater than the total image area
while cont<dimprod
% if moving along x and not past boundary dimension
if slittox == 1 && (ii+1)<=dimx
ii = ii+1;
jj = jj;
zigzag(ii,jj)=cont;
cont = cont+1;
slittox = 0;
last = 1;
continue;
end
% if moving along x and past boundary dimension
if slittox == 1 && (ii+1)>dimx && (jj+1<=dimy)
ii = ii;
jj = jj+1;
zigzag(ii,jj)=cont;
cont = cont+1;
slittox = 0;
last = 1;
continue;
end
% if moving along y and not past boundary dimension
if slittoy == 1 && (jj+1)<=dimy
ii = ii;
jj = jj+1;
zigzag(ii,jj)=cont;
cont = cont+1;
slittoy = 0;
last = 0;
continue;
end
% if moving along y and past boundary dimension
if slittoy == 1 && (jj+1)>dimy && (ii+1<=dimx)
ii = ii+1;
jj = jj;
zigzag(ii,jj)=cont;
cont = cont+1;
slittoy = 0;
last = 0;
continue;
end
if (slittox == 0 && slittoy == 0) && last == 1
if ii-1>=1 && jj+1<=dimy
ii=ii-1;
jj=jj+1;
zigzag(ii,jj)=cont;
cont = cont+1;
continue;
else
slittox = 0;
slittoy = 1;
continue;
end
end
if (slittox == 0 && slittoy == 0) && last == 0
if ii+1<=dimx && jj-1>=1
ii=ii+1;
jj=jj-1;
zigzag(ii,jj)=cont;
cont = cont+1;
continue;
else
slittox = 1;
slittoy = 0;
continue;
end
end
end
zigzag(dimx,dimy)=dimprod;
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% generate 2D DCT for orignal image
t = dct2(ingresso);
% vectorize the DCT result
vettore_t = t(:);
% define zero array same size as DCT vector
vettore_t_zigzag = zeros(size(vettore_t));
% vectorize zigzag expansion for original image
vettore_zigzag = zigzag(:);
% assign values to zero array at index of zigzag position
for ii=1:length(vettore_t)
vettore_t_zigzag(vettore_zigzag(ii)) = vettore_t(ii);
end
% assign to result
result = vettore_t_zigzag(2:Lout+1);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------