-
Notifications
You must be signed in to change notification settings - Fork 2
/
segFoci3D.m
31 lines (25 loc) · 1.05 KB
/
segFoci3D.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
function fociSegData = segFoci3D(img,thresholdScale, minFociVox,gaussFilt)
%% Adam Tyson | 11/12/2017 | [email protected]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input:
% img - 3D image of foci to be segmented
% thresholdScale - change sensitivity of threshold (roughly 0.5-2)
% gaussFilt - width of gaussian filter used to smooth foci prior to segmentation
% minFociVox - minimum foci volume in voxels (smaller than this are removed)
% output:
% fociSegData - a binary image of the segmented foci
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img=double(img);
img=scaleIm(img, max(img(:))); % scale slice by slice
% prep
foci.smo=imgaussfilt(img,gaussFilt); % smooth
% threshold
levelOtsu=multithresh(foci.smo,2);
foci.bin=img;
foci.bin(img<thresholdScale*levelOtsu(2))=0;
foci.bin(foci.bin>0)=1;
% clean up
foci.smallRem=logical(bwareaopen(foci.bin, minFociVox)); % remove small objects rather than erode (need double for doubleColorMap later on)
fociSegData=foci.smallRem;
% figure; imshow3D(fociSegData)
end