-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTracking.m
160 lines (128 loc) · 6.79 KB
/
Tracking.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
function [Trace_All, ImageInfo] = Tracking(FileName, varargin)
%
% [Trace_All, ImageInfo] = Tracking(FileName)
% [Trace_All, ImageInfo] = Tracking(FileName, 'Parameter', value)
%
% Tracking(FileName) tracking the fluorescent cells in movie (.nd2 or .tif) of file name
% of 'FileName'.
%
% The funtion will return a cell data Trace_All and a structure data ImageInfo. Each cell
% in Trace_All will be one trajectories in the movie. The rest tracking result will be
% saved in '.mat' file in the same path.
%
% Multichannel images is acceptable.
% [Trace_All, ImageInfo] = Tracking(FileName, 'ChannelNum', 2)
% will automatically split the stack into 2 channels. The darkest channel will be taken as
% the fluorescent channel for tracking.
%
% [Trace_All, ImageInfo] = Tracking(FileName, 'AutoThreshold', 'off', 'BlurSize', 1.5, ...
% 'ExtensionRatio', 2, 'ActiveContourTimes', 5)
% will set the thereshold manually. You can find the specific introduction for each parameter in
% README.md.
%
% Initialization the default parameter
disp('--------------------------------------------------------------------------------')
disp('Initialization...')
ChannelNum = 1;
Normalization = 'on';
AutoThreshold = 'on';
AutoCellSize = 120;
ActiveContourStatus = 'off';
ActiveContourTimes = 5;
Method = 'Fluorescent';
% Method = 'LocalMaximal';
Range = 6;
Tolerance = 'auto';
% Reload the parameters input by user
if isempty(varargin)
else
for i = 1:(size(varargin, 2) / 2)
AssignVar(varargin{i * 2 - 1}, varargin{i * 2})
end
end
% Check the Information of the movie
if exist('TrackChannel', 'var')
ImageInfo = ImageFileInfo(FileName, ChannelNum, TrackChannel);
else
ImageInfo = ImageFileInfo(FileName, ChannelNum);
end
% Background Normalization
if strcmp(Method, 'Fluorescent') || strcmp(Method, 'PhaseContrast')
if strcmp(Normalization, 'on')
disp('--------------------------------------------------------------------------------')
disp('Background normalization...')
Background_nor = BackgroundNormalization(ImageInfo, 'Method', Method);
else
disp('--------------------------------------------------------------------------------')
disp('Background normalization off')
if strcmp(Method, 'Fluorescent')
Background_nor = ones(ImageInfo.ImageHeight, ImageInfo.ImageWidth);
elseif strcmp(Method, 'PhaseContrast')
Background_nor = zeros(ImageInfo.ImageHeight, ImageInfo.ImageWidth);
end
end
% Test for the best threshold.
if strcmp(AutoThreshold, 'on')
disp('--------------------------------------------------------------------------------')
disp('Auto threshold tesing')
[BlurSize, ExtensionRatio] = ThresholdTest(ImageInfo, Background_nor,'Method',Method);
else
if exist('BlurSize', 'var')
else
BlurSize = 1.5;
end
if exist('ExtensionRatio', 'var')
else
ExtensionRatio = 2;
end
end
disp(['The BlurSize and ExtensionRatio is set as ', num2str(BlurSize), ' and ', num2str(ExtensionRatio)])
% Process Cell Size.
disp('--------------------------------------------------------------------------------')
disp('Process Cell Size')
MeanCellSize = CellSizeTest(ImageInfo, Background_nor, BlurSize, ExtensionRatio, 'AutoCellSize', AutoCellSize, 'ActiveContourStatus', ActiveContourStatus, 'ActiveContourTimes', ActiveContourTimes, 'Method', Method);
disp(['The mean cell size is about ', num2str(MeanCellSize)])
% Transform the gray images into B/W image
disp('--------------------------------------------------------------------------------')
disp('B/W Image Calculating...')
[CellRegion_All, ~] = BW_All(ImageInfo, Background_nor, BlurSize, ExtensionRatio, 'CellSizeControlStatus', AutoCellSize, 'ActiveContourStatus', 'on', 'ActiveContourTimes', ActiveContourTimes, 'Method', Method);
elseif strcmp(Method, 'LocalMaximal')
% Transform the gray images into B/W image
disp('--------------------------------------------------------------------------------')
disp('B/W Image Calculating...')
[CellRegion_All, ~] = LM_Process(ImageInfo, Range, Tolerance);
end
% PartOne find the locations of cells
disp('--------------------------------------------------------------------------------')
disp('Finding cells locations ...')
[Cell_Centroid, Cell_Size, Cell_Index, V, C] = PositionLocator(CellRegion_All, ImageInfo);
% PartTwo link the cells between neighbour frames
disp('--------------------------------------------------------------------------------')
disp('Tracking cells between neighbour frames')
[trace_result] = TrackCellBetweenFrames(Cell_Centroid, Cell_Size, Cell_Index, V, C);
% PartThree connect all the traces
disp('--------------------------------------------------------------------------------')
disp('Connect cells traces')
[Trace_All] = TraceConnector(trace_result);
disp('--------------------------------------------------------------------------------')
disp('Saving data!')
clear('i')
disp('--------------------------------------------------------------------------------')
save([ImageInfo.Path, 'Trace ', ImageInfo.FileName, '.mat'])
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% __ ___ _ _ _ ____ %
% \ \ / / | | | | | / \ | __ ) Wu Lab at CUHK %
% \ \ /\ / /| | | | | | / _ \ | _ \ All rights reserved %
% \ V V / | |_| | | |___ / ___ \| |_) | www.phy.cuhk.edu.hk/ylwu %
% \_/\_/ \___/ |_____/_/ \_\____/ J. Z.: [email protected] %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% _ _ ____ ___ ____ %
% | | / \ / ___| / _ \ | __ ) Wu Lab at CUHK %
% _ | | / _ \ | | | | | | | _ \ All rights reserved %
% | |_| | / ___ \ | |___ | |_| | | |_) | https://jacobzuo.github.io %
% \___/ /_/ \_\ \____| \___/ |____/ J. Z.: [email protected] %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %