-
Notifications
You must be signed in to change notification settings - Fork 2
/
cellsegT0.m
37 lines (31 loc) · 1.43 KB
/
cellsegT0.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
function [cellsSeg, volCells]=cellsegT0(img, thresholdScale, cellVolThresh, cellHoleThresh)
%% Adam Tyson | 08/12/2017 | [email protected]
% function to segment out very low intensity cells at t=0
% input: img - 3D stack of cells, in which most of the dynamic range is
% taken up by non cellular objects
% thresholdScale - a fudge factor to change the threshold (should be
% able to keep at 1)
% cellVolThresh - min volume of "cells", below which they are removed
% cellHoleThresh - max volume of "holes" inside cells to be filled in"
% output: cellsSeg - segmented image of cells
% volCells - fraction of the 3D image taken up by cells
%% prep
data.sub=backSub3D(img);
sze=size(img);
filterWidth=round(0.004*sqrt(sze(1)*sze(2)));
data.smo = loop2dsmooth(img, filterWidth);
data.firstsub= bsxfun(@minus,data.smo, data.smo(:,:,1));
data.scaled=(data.firstsub-min(data.firstsub(:)))/(max(data.firstsub(:))-min(data.firstsub(:)));
%% threshold
[~, rosinThresh] = cutFirstHistMode(data.scaled,0);
threshold=rosinThresh*thresholdScale;
data.thresh=data.scaled;
data.thresh(data.thresh<threshold)=0;
data.thresh(data.thresh>0)=1;
%% tidy up
data.opened=double(bwareaopen(data.thresh, cellVolThresh));%remove noise
data.fill=~bwareaopen(~data.opened, cellHoleThresh); % fill in holes
%% values to return
cellsSeg=data.fill;
volCells=sum(data.fill(:))/numel(data.fill);
end