% THS:
% c: (TODO: should be the average red cell size)
function [schizonts] = DetectionOfSchizonts(THS, c)
-
+
+ schizontsConnectivityMin = 3; % Minimum cluster size when detecting schizonts.
redCellsSE = mmsedisk(c, '2D', 'OCTAGON');
schizonts = zeros(size(THS), 'uint8');
end
n = n + 1;
end
+
+ %% Check the Hausdorff distance between each set combination by dilation -> create a graph by populate 'adjacencyMatrix'.
+ adjacencyMatrix = spalloc(length(sets), length(sets), 500);
+ addedSet = zeros(length(sets));
- %% Check the Hausdorff distance between each set combination by dilation.
for i = 1:length(sets)
setA = sets{i};
- if isempty(setA)
- continue
- end
dilatedSetA = mmdil(setA, redCellsSE);
for j = 1:length(sets)
setB = sets{j};
- if isequal(setB, setA) || isempty(setB)
+ if isequal(setB, setA) || addedSet(j)
continue
end
if (dilatedSetA & setB) == setB % If B is a subset of A -> there are both in a Hausdorff distance of 2*c.
- schizonts = schizonts | setA | setB;
- sets{i} = [];
- sets{j} = [];
+ adjacencyMatrix(i, j) = 1;
+ adjacencyMatrix(j, i) = 1;
+ addedSet(i) = 1;
end
end
+ end
+
+ %% Fill 'schizonts' by testing the connectivity of each cluster set.
+ [~, C] = graphconncomp(adjacencyMatrix, 'Directed', false, 'Weak', true);
+ n = 1;
+ while 1
+ relatedSets = C == n;
+ if ~any(relatedSets)
+ break
+ end
+ if sum(relatedSets) >= schizontsConnectivityMin
+ for i = find(relatedSets)
+ if ~isempty(sets{i})
+ schizonts = schizonts | sets{i};
+ sets{i} = [];
+ end
+ end
+ end
+ n = n + 1;
end
imwrite(schizonts, '../output/schizonts.png')