From: Greg Burri Date: Fri, 1 May 2015 14:35:47 +0000 (+0200) Subject: Add a connectivity parameter when identifying the schizonts. X-Git-Url: http://git.euphorik.ch/?a=commitdiff_plain;h=20705acd23212f557b714364b959a602dd1fd3e9;p=malaria.git Add a connectivity parameter when identifying the schizonts. --- diff --git a/src/DetectionOfSchizonts.m b/src/DetectionOfSchizonts.m index c2b53ee..823d9c5 100644 --- a/src/DetectionOfSchizonts.m +++ b/src/DetectionOfSchizonts.m @@ -2,7 +2,8 @@ % 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'); @@ -20,25 +21,44 @@ function [schizonts] = DetectionOfSchizonts(THS, c) 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')