forked from ChuiJianFeng/Zebrafish-Analyzing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Distance.m
79 lines (75 loc) · 2.41 KB
/
Distance.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
%% Distance measurement condition 43s 10320 frame
% stadard
point = cameraParams.ReprojectedPoints;
cal = imread('check_board1/1.png');
figure, imshow(cal);
hold on;
num =1;
plot(point(1,1,num),point(1,2,num),'.r','MarkerSize',10);
% plot(point(144,1,num),point(144,2,num),'.r','MarkerSize',10);
r = [point(67,1,1)-point(77,1,1) point(67,2,1)-point(77,2,1)];
r2 = [point(1,1,1)-point(144,1,1) point(1,2,1)-point(144,2,1)];
len = sqrt(sum(r.^2,2)); %848.9442
len2 = sqrt(sum(r2.^2,2)); %848.9442
d = len/10;
d2 = len2/13;
all = len+d;
all2 = len2+d2*2;
scale_width = all / 10;
scale__heigh = all2 / 19;
%% Distance measurement
% Initial value.
% 長x寬 : 19 x10 cm 高:深度 20 cm 拍攝時水位會控制在8cm
fs = 240;
s = 1/fs;
% t = (1:80*240)/fs;
fnum = 19297;
t = (1:fnum)/fs;
scale_heigh = 1920/19;
scale_width = 1080/10;
% head
r = [diff(coordi{point_Id(1)}(1:length(t),1))/scale_heigh diff(coordi{point_Id(1)}(1:length(t),2))/scale_width];
dt1 = sqrt(sum(r.^2,2));
dt1 = dt1*10;
spd1 = dt1./s;
%body
r = [diff(coordi{point_Id(2)}(1:length(t),1))/scale_heigh diff(coordi{point_Id(2)}(1:length(t),2))/scale_width];
dt2 = sqrt(sum(r.^2,2));
dt2 = dt2*10;
spd2 = dt2./s;
fprintf("Head\n");
fprintf("%.2f\n", sum(dt1));
fprintf("%.3f\n", sum(dt1)/ t(end));
fprintf("Body\n");
fprintf("%.2f\n", sum(dt2));
fprintf("%.3f\n", sum(dt2)/ t(end));
%%
t = (1:10320-99)/240;
spd0621= spd0621.*~(spd0621> 100);
% spd0788= spd0788.*~(spd0788> 80);
% spd1212= spd1212.*~(spd1212> 100);
figure(1),
subplot(311),
plot(t,[0;spd0621(100:end)],'g', 'LineWidth',1);
% legend(['Healthy (Average speed: ' num2str(round(average_velocity1,2)) ' kpx /s ) '],'Location','northwest');
legend('Healthy');
xlabel("Time (sec)");
% ylabel('Velocity (kilopixels / s)');
xlim([0 43])
subplot(312),
plot(t,[0;spd0788(100:end)],'r', 'LineWidth',1);
% legend(['MPTP (Average speed: ' num2str(round(average_velocity2,2)) ' kpx /s ) '],'Location','northwest');
legend('MPTP');
xlabel("Time (sec)");
ylabel('Velocity (mm / s)');
xlim([0 43])
subplot(313),
plot(t,[0;spd1212(100:end)],'b', 'LineWidth',1);
% legend(['Sham (Average speed: ' num2str(round(average_velocity3,2)) ' kpx /s ) '],'Location','northwest');
% plot(t,[0;spd9854(361:10800)],'g', 'LineWidth',2);
legend('Sham');
xlabel("Time (sec)");
% ylabel('Velocity (kilopixels / s)');
xlim([0 43])
% hold off;
% saveas(gcf,'velocity_long.png')