-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractNuclei.m
More file actions
50 lines (44 loc) · 1.58 KB
/
ExtractNuclei.m
File metadata and controls
50 lines (44 loc) · 1.58 KB
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
function Nuclei = ExtractNuclei(imagename,T0,ShowImages)
% T0: intensity threshold for nucleus identification
% (default: 32)
AreaMin = 1000; % Nuclear area lower threshold
fsz = 40; % font-size in nucleus annotation image
% Read images
fprintf(['Processing sample' ' ' imagename '...\n']);
A_dapi = imread([imagename '_ch00_hilo.tif']);
% Filter and segment DAPI channel
Nuclei = (A_dapi >= T0);
% Detect individual Nuclei
Nuclei = bwmorph(Nuclei,'clean');
Nuclei = imclearborder(Nuclei);
[component,Nx] = bwlabel(Nuclei);
Nuclei_annot = uint8(255*Nuclei);
N = 0; % Number of nuclei
% Extract individual cells
for k=1:Nx
C = (component == k);
Stats = regionprops(C);
if Stats.Area>=AreaMin
N = N+1;
Index = int2str(N);
fprintf(['Extracting nucleus #' Index ' ' '...\n']);
Nucleus = (component == k);
Stats = regionprops(Nucleus);
x = round(Stats.Centroid(1)); y = round(Stats.Centroid(2));
Nuclei_annot = insertText(Nuclei_annot,[x-20,y-20],Index,'TextColor','red',...
'FontSize',fsz,'BoxOpacity',0);
end;
end;
% Write nuclei enumeration image
ImTitle = strcat(imagename,'_ch00_seg');
if ShowImages
figure('Position',[100 100 700 500]);
imshow(A_dapi,'InitialMagnification','Fit');
title(imagename);
figure('Position',[900 100 700 500]);
imshow(Nuclei_annot,'InitialMagnification','Fit');
title(ImTitle);
end;
imwrite(Nuclei_annot,strcat(ImTitle,'.jpg'),'jpg');
%cd ..
end