-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobjectOrientedSegmentation.m
119 lines (109 loc) · 4.56 KB
/
objectOrientedSegmentation.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
%-------------------------------------------------------------------------%
%------------- Object Oriented Segmentation of Cell Nuclei ---------------%
%------------------- Fluorescence Microscopy Images ----------------------%
%-------------------------------------------------------------------------%
%
% This work introduces a new nucleus segmentation algorithm that relies on
% using gradient information not at the pixel-level but at the object-level.
% To this end, it proposes to decompose an image into smaller homogeneous
% subregions, define edge-objects at four different orientations to encode
% the gradient information at the object-level, and devise a merging step,
% in which the edge-objects vote for subregion pairs along their orientations
% and the pairs are iteratively merged if they get sufficient votes from
% multiple orientations.
%
% NOTE: The following source codes and executable are provided for
% research purposes only. The authors have no responsibility for any
% consequences of use of these source codes and the executable. If you
% use any part of these codes, please cite the following paper.
%
% C. F. Koyuncu, R. C. Atalay, and C. Gunduz-Demir, "Object Oriented
% Segmentation of Cell Nuclei in Fluorescence Microscopy Images,"
% submitted to IEEE Trans. Med. Imag.
%
%
% If that is YOUR FIRST USE of this program run makeAll file once.
% This file produces a Matlab executables and adds necessary folders into
% Matlab path.
%
% Please contant Can Fahrettin Koyuncu at [email protected] for
% further questions.
%
%
% This function takes 5 inputs and outputs the segmentation results
% inputName: Image filename (an RGB image)
% -----> Edge-object definition <-----
% tsize: Minimum height/width for a component to be an edge-object
% -----> Subregion merging <-----
% dmax: Maximum distance within which an edge-object can vote for
% a subregion
% tvote: Minimum score that a subregion pair should take from at
% least one vertical (left or right) and at least one
% horizontal (top or bottom) edge type to be qualified for
% merging
% -----> Postprocessing <-----
% tarea: Minimum area for a subregion to be a nucleus
%
% Internal parameters:
% -----> Sub-region partitioning <-----
% nslic: Expected number of superpixels of the SLIC algorithm
% kslic: Spatiality constant of the SLIC algorithm for adjusting
% the weight of L, a, b values over coordinates in clustering
% -----> Postprocessing <-----
% rfilter: Radius of a majority
%
%
% Example use:
% segmRes = objectOrientedSegmentation ('hepg2f_1.jpg', 5, 20, 0.1, 400);
%
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
function segmRes = objectOrientedSegmentation (inputName, tsize, dmax, tvote, tarea)
% % Internal parameters
nslic = 4000;
kslic = 5;
rfilter = 3;
im = imread (inputName);
[L, ~, ~] = RGB2Lab(im);
% % mask
L = L / max(max(L));
mask = im2bw(L, graythresh(L));
% % subregions
[newSlic, ~] = slicmex(im, nslic, kslic);
newSlic = double(newSlic) + 1;
newSlic(mask==0)= 0;
newSlic = relabelImage(newSlic);
connectivity = 8;
d = 3;
otsuKs = 0.5:0.5:2.0;
rights = []; lefts = [];
tops = []; bottoms = [];
for otsuK = otsuKs
[right, left, top, bottom] = identifyPrims (L, d, tsize, connectivity, mask, otsuK);
if otsuK == otsuKs(1)
newSlic = findSubRegions (newSlic, left, right, top, bottom);
end
newSlic = objOrientSegm (newSlic, right, left, top, bottom, tvote, dmax, connectivity, 1, tarea);
rights = cat(3, rights, right);
lefts = cat(3, lefts, left);
tops = cat(3, tops, top);
bottoms = cat(3, bottoms, bottom);
end
segmRes = postProcessing (newSlic, tarea, mask, rights, lefts, tops, bottoms, rfilter);
end
function labeled = relabelImage(map)
labels = unique(nonzeros(map))';
label_map = zeros(1, max(labels));
for label = labels
ind = find(labels == label);
label_map(label) = ind(1);
end
labeled = zeros(size(map));
for i=1:size(labeled,1)
for j=1:size(labeled,2)
if map(i,j) > 0
labeled(i,j) = label_map(map(i,j));
end
end
end
end