-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_oct.m
167 lines (149 loc) · 4.19 KB
/
main_oct.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
clc
clear
%INPUT IMAGE
%I = imread('smiley-face-sm.png','png');
I = imread('images/bikeniteinv.png','png');
%I = imread('test2.gif','gif');
%I = imread('bikenite5.png','png');
if min(I(:,:,1)) == 255
I=I(:,:,2);
else
I=I(:,:,1);
end
I = flipud(I); %flip image data
height = size(I,1);
width = size(I,2);
centx=width/2;
centy=height/2;
maxcolour = max(I(1:end));
polaries=[]; %Init matrix of ones to store information on
index=0;
thres = 223;
for x=1:width
for y=1:height
matx = y;
maty = x;
neux = x-centx;
neuy = y-centy;
radius = sqrt(neux^2+neuy^2);
angle = atan(neux/neuy);
if I(maty,matx)<thres
index=index+1;
if neuy <0 && neux>=0
% angle = pi-angle
radius = -radius;
elseif neux <0 && neuy<0
radius = -radius;
end
%negative radius solution
if radius<0
radius =-radius;
if angle>0
angle=angle-pi();
else angle<0
angle=angle+pi();
end
end
%negative angle solution
if angle<0
angle=angle+2*pi();
end
polaries(index,2)=radius;
polaries(index,1)=angle;
polaries(index,3)=I(maty,matx);
end
end
end
disp('one down');
%Plot results of the straight import
%figure(1);
%polar(polaries(1:end,1),polaries(1:end,2),'.');
%% SPECS of display
%disp_circ_pix=37; %37cp |o|o|o|o|o|o|o|o|o| i.e 16 LEDS per side
disp_circ_pix=37; %37cp |o|o|o|o|o|o|o|o|o| i.e 16 LEDS per side
excl_center=5; %5cp - circular rings, middle ring is a circle
num_centers = round(disp_circ_pix/2); %including 0th center
ang_reso = 180; %count per rotation
seg_wid = 2*pi/ang_reso; %rad
disp('two down')
%% INITIALISE CONTENTS
res = zeros(disp_circ_pix,ang_reso); %rows, cols
rad_bounds = [0,0.5:1:disp_circ_pix/2];
rad_centers = [0,1:disp_circ_pix/2];
ang_centers = [0:seg_wid:2*pi-seg_wid];
ang_bounds = [-seg_wid/2,seg_wid/2:seg_wid:2*pi-seg_wid/2];
%OUTPUT IMAGE DETAILS
output = zeros(ang_reso,size(rad_centers,2));
%scale matrix for given theoretical concentric width (disp_circ_pix)
scale_ratio = disp_circ_pix/max(width,height);
for i=1:size(polaries,1)
polaries(i,2)=polaries(i,2)*scale_ratio;
end
%analysie each pixel in the main image and see which hole they fit into and
%place one count into each hole
figure(2);
clf;
polar(polaries(1:end,1),polaries(1:end,2),'.') %polaries in format rad,ang,int. r,a, only important
for i=1:size(polaries,1)
angle = polaries(i,1);
radius = polaries(i,2);
a_ind = 0;
r_ind = 0;
for j=1:ang_reso %ANGLE
larc = ang_bounds(j);
rarc = ang_bounds(j+1);
if angle>=larc && angle<rarc
a_ind = j;
break
end
end
%if
for k=1:num_centers
radmin = rad_bounds(k);
radmax = rad_bounds(k+1);
if radius>radmin && radius<=radmax
r_ind = k;
break
end
end
if r_ind && a_ind
output(a_ind,r_ind)=output(a_ind,r_ind)+1;
end
end
disp('three down')
%% condition data
for j=1:numel(output)
if output(j)>0
output(j)=1;
else
output(j) = 0;
end
end
%% final representation plot
figure(1);
clf;
ang = []
rho = []
hold on
for j=1:ang_reso %ANGLE
for k=4:size(rad_centers,2)
if output(j,k)>0
ang = [ang,ang_centers(j)];
rho = [rho,rad_centers(k)];
end
end
end
j=polar(ang,rho,'ro'); %plot theta, rho
set(j,'markerfacecolor','r')
axis([-20 20 -20 20])
axis equal
disp('done');
%% strip out data to create a matrix file for the uC
% first leave only 16 pixels
output=output(:,end-15:end);
fileID = fopen('img.bin','w');
for i=1:size(output,1)
fwrite(fileID, logical(output(i,1:8)),'ubit1',0,'b');
fwrite(fileID, logical(output(i,9:end)),'ubit1',0,'b');
end
fclose(fileID);