-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessFramesIF.m
97 lines (82 loc) · 2.92 KB
/
processFramesIF.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
%processFramesIF(data, varargin) runs CCP detection on all channels of fixed-cell
% data sets for colocalization studies. To determine the level of chance
% colocalization, a set of Gaussian fits at random locations is also calculated.
%
% Input:
% data : structure with fields
% .channels : cell array of paths to TIFF files
% .results : path to results file
%
% Options:
% 'Overwrite' : true|{false}
%
% The output structure written to the results file contains the fields
% .ps : result of pointSourceDetection at CCP locations, for all channels
% .psRand : result of Gaussian fitting at random locations, for all channels
% .mask : cell mask
% Francois Aguet, 01/2014
% Philippe Roudot 12/2017
function processFramesIF(data, varargin)
ip = inputParser;
ip.CaseSensitive = false;
ip.addRequired('data');
ip.addParameter('Overwrite', false, @islogical);
ip.addParameter('validateMask', true, @islogical);
ip.parse(data, varargin{:});
nd = numel(data);
%% Use mask validation
allMasks = getCellMask(data, 'Overwrite', ip.Results.Overwrite, 'Validate', ip.Results.validateMask);
if(~iscell(allMasks))
allMasks={allMasks};
end
parfor i = 1:nd
if ~(exist(data(i).results, 'file')==2) || ip.Results.Overwrite
fprintf('Processing %s ... ', getDirFromPath(data(i).results));
nc = numel(data(i).channels);
sigma = 1.5+zeros(1,nc); % change to input
ch = cell(1,nc);
for c = 1:nc
ch{c} = imread(data(i).channels{c});
end
mask=allMasks{i};
% mask = maskFromFirstMode(ch{1});
% CC = bwconncomp(~mask, 8);
% np = cellfun(@numel, CC.PixelIdxList);
% mask = imfill(mask);
% bgIdx = vertcat(CC.PixelIdxList{np<100});
% mask(bgIdx) = 1;
% run spot detection
ps=cell(1,nc);
for c = 1:nc
ps{c} = pointSourceDetection(ch{c}, sigma(c), 'Mode', 'xyAc', 'Mask', mask);
end
ps=[ps{:}];
% random positions
np = max(arrayfun(@(i) numel(i.x), ps));
N = 10*np;
w = max(ceil(4*sigma));
% random positions
xr = [];
yr = [];
[ny,nx] = size(mask);
while numel(xr)<N
xcand = 1+w+(nx-2*w-1)*rand(1,N);
ycand = 1+w+(ny-2*w-1)*rand(1,N);
idx = mask(sub2ind([ny nx], round(ycand), round(xcand)));
xr = [xr xcand(idx~=0)]; %#ok<*AGROW>
yr = [yr ycand(idx~=0)]; %#ok<*AGROW>
end
xr = xr(1:N);
yr = yr(1:N);
psRand=cell(1,nc);
for c = 1:nc
psRand{c} = fitGaussians2D(double(ch{c}), xr, yr, [], sigma(c), [], 'Ac'); %#ok<NASGU>
end
psRand=[psRand{:}];
% save mask + detections
saveData(data(i).results, ps, psRand, mask);
fprintf('done.\n');
end
end
function saveData(res,ps,psRand,mask)
save(res, 'ps', 'psRand', 'mask');