-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcp_centroids.m
43 lines (37 loc) · 1.48 KB
/
cp_centroids.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
function [blobpositions, bloblabels, quality] = cp_centroids(input_dir, position)
config = get_config();
cycles = config('cycles');
types = config('types');
key = config('label_cellprofiler');
S = load(sprintf('%s/%s', input_dir, config('mat_cellprofiler')));
m = S.handles.Measurements.blobs;
% position data exists in these for each image; ignore all but the first
% since these are the same in every image.
blobpositions = cat(2, ...
m.Location_Center_X{position}, ...
m.Location_Center_Y{position});
% shift to matlab-based positions (i.e start at 1 rather than 0)
blobpositions = blobpositions + 1;
intensity = cell([1 numel(cycles)]);
for cycleidx=1:numel(cycles)
cycle = cycles(cycleidx);
intensity{cycleidx} = [];
for typeidx=1:numel(types)
intensity{cycleidx} = cat(2, ...
intensity{cycleidx}, ...
m.(sprintf(key, cycle, typeidx)){position} ...
);
end
end
% accumulate the positions into the sequence format
bloblabels = zeros([size(blobpositions, 1) 1]);
quality = inf([size(blobpositions, 1) 1]);
shift = 10 ^ (numel(cycles) - 1);
for i=1:numel(cycles)
total = sum(intensity{i}, 2);
[maxes, indexes] = max(intensity{i}, [], 2);
bloblabels = bloblabels + (indexes .* shift);
shift = shift / 10;
quality = min(double(maxes) ./ total, quality);
end
end