forked from ZXY1231/WormTrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
executable file
·79 lines (67 loc) · 2.38 KB
/
main.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
% Main function to extra features from worm image
%
% | Version | Author | Date | Commit
% | 0.1 | ZhouXY | 18.07.19 | The init version
% | 0.2 | H.F. | 18.08.28 |
% TODO: put the parameters outside function but main function
% ���追踪
clear all;
warning('off','all'); % Close all warning
tic;
% Parameters
source_path = '/home/hf/iGEM/Results/20180904/DifussionTest7min/';
result_path ='/home/hf/iGEM/Results/20180904/';
thresh = 0.991;
small = 50;
big = 600;
imges = dir([source_path '*.tif']);
imge_num = length(imges);
CentroidsLocates = cell(imge_num,1);
leng = imge_num;
%leng = 16 ; %debug
% Handling background and worms localization
parfor i =1:leng
img = imread([imges(i).folder '/' imges(i).name]);
img = img(516:1978, 588:1982);
contrastAdjusted = BgNormal(img);
imwrite(img, [result_path '/Normalize/' imges(i).name '.png']);
[imgx, imgy, imgbwthresh, imgremoved] = BgThresh(contrastAdjusted,thresh,small,big);
imwrite(imgbwthresh, [result_path 'Thresh/' imges(i).name '.png']);
imwrite(imgremoved, [result_path 'Remove/' imges(i).name '.png']);
CentroidsLocates{i,1} = cat(1,imgx,imgy);
%printf('Remain %d', leng-i);
end
% The worm location in first frame
PreLocaX = CentroidsLocates{1,1}(1,:);
PreLocaY = CentroidsLocates{1,1}(2,:);
% Postions of each worm
PointsDynamics = cell(length(PreLocaX),1);
for i = 1:length(PreLocaX)
% Save each worm's location in frist frame
PointsDynamics{i,1} = [PreLocaX(i) PreLocaY(i)];
end
%
for i = 2:leng
PostLoca = CentroidsLocates{i,1};
[NeX,NeY] = NextFrameNearestPoint(PreLocaX,PreLocaY,PostLoca(1,:),PostLoca(2,:));
PreLocaX = NeX;
PreLocaY = NeY;
% Each worm
for j = 1:length(PreLocaX)
% Stack the every point
PointsDynamics{j,1} = cat(1,PointsDynamics{j,1},[PreLocaX(j) PreLocaY(j)]);
end
%fprintf(flocates,'%d\n%lf\n%lf\n\n',i,PreLocaX,PreLocaY);
end
% Write each worm's localtion to file
flocates = fopen([result_path 'DiffussionTest7min.localtion'],'w');
csvwrite([result_path 'DiffussionTest7min.local'],cell2mat(PointsDynamics'));
for i = 1:length(PointsDynamics)
fprintf(flocates, 'Point %d', i);
fprintf(flocates, '\r\nx\r\n');
fprintf(flocates, '%f\r\t', PointsDynamics{i,1}(:,1));
fprintf(flocates, '\r\ny\r\n');
fprintf(flocates, '%f\r\t', PointsDynamics{i,1}(:,2));
fprintf(flocates, '\r\n\r\n');
end
toc;