From 04caa8d23a6c86f24291a7813232c6601a48fa79 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 1 May 2015 14:58:50 +0200 Subject: [PATCH] * Use 'mmlabel' to detect schizonts instead of a complex code involving reconstructions. * Use of a regional minimum for the saturation component. --- src/DetectionOfParasites.m | 24 +++++++++++++++--------- src/DetectionOfSchizonts.m | 17 +++++++---------- src/Main.m | 24 ++++++++++++++++++------ src/SegmentationOfRedCells.m | 5 ++++- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/DetectionOfParasites.m b/src/DetectionOfParasites.m index 8d3b2be..830f484 100644 --- a/src/DetectionOfParasites.m +++ b/src/DetectionOfParasites.m @@ -23,14 +23,16 @@ function [THS, c] = DetectionOfParasites(imgRGB) % p. 136: median filter to smooth the noise and % area closing to enhance the bright objects and make flatter, darker and cleaner the image background. - imgFiltered{1} = mmareaclose(medfilt2(imgH, [5, 5]), 400); % Hue. - imgFiltered{2} = mmareaclose(medfilt2(imgS, [5, 5]), 400); % Saturation. - imgFiltered{3} = mmareaclose(medfilt2(imgV, [5, 5]), 400); % Value. + medianFilterWindow = [5, 5]; + imgFiltered{1} = mmareaclose(medfilt2(imgH, medianFilterWindow), 200); % Hue. + % We use an opening fot the saturation because the parasites are darker than the rest of the image. + imgFiltered{2} = mmareaopen(medfilt2(imgS, medianFilterWindow), 200); % Saturation. + imgFiltered{3} = mmareaclose(medfilt2(imgV, medianFilterWindow), 200); % Value. imwrite(imgFiltered{1}, '../output/imgHFiltered.png'); imwrite(imgFiltered{2}, '../output/imgSFiltered.png'); imwrite(imgFiltered{3}, '../output/imgVFiltered.png'); - + % Shading correction with a Top-hat transformation (p. 673). % Not in the article -> disable for the moment, not needed. % imgHFiltered = mmopenth(imgHFiltered, mmsedisk(80, '2D', 'OCTAGON')); @@ -47,7 +49,7 @@ function [THS, c] = DetectionOfParasites(imgRGB) sizeDistribution = zeros(redCellMaxSize, 1); parfor k = 1:redCellMaxSize - SE = mmsedisk(k, '2D', 'OCTAGON'); % TODO : tester avec 'euclidean' + SE = mmsedisk(k, '2D', 'OCTAGON'); % 'EUCLIDEAN' is more precise. imgOpened = mmopen(imgFiltered{2}, SE); A = funVolume(imgOpened); N = 1 - A / volImg; @@ -70,11 +72,15 @@ function [THS, c] = DetectionOfParasites(imgRGB) %% Regional extrema % The size of the SE (c) must be equal to the size of red cells (see granulometry below). - regionalMaxSE = mmsedisk(c, '2D', 'OCTAGON'); + regionalExtremumSE = mmsedisk(c, '2D', 'OCTAGON'); + % The functions 'mmregmax' and 'mmregmin' are very time consuming! parfor i = 1:3 - % This operation is very time consuming! - M{i} = mmregmax(imgFiltered{i}, regionalMaxSE); + if i == 2 + M{i} = mmregmin(imgFiltered{i}, regionalExtremumSE); % Special case for the saturation component. + else + M{i} = mmregmax(imgFiltered{i}, regionalExtremumSE); + end end nucleiSE = mmsedisk(nucleiRadius, '2D', 'OCTAGON'); @@ -85,7 +91,7 @@ function [THS, c] = DetectionOfParasites(imgRGB) muS = funVolume(uint8(MHS) .* imgFiltered{2}) / volumeMHS; TH = im2bw(imgFiltered{1}, double(muH) / 255); - TS = im2bw(imgFiltered{2}, double(muS) / 255); + TS = ~im2bw(imgFiltered{2}, double(muS) / 255); THS = TH & TS; diff --git a/src/DetectionOfSchizonts.m b/src/DetectionOfSchizonts.m index e16327d..c2b53ee 100644 --- a/src/DetectionOfSchizonts.m +++ b/src/DetectionOfSchizonts.m @@ -8,21 +8,18 @@ function [schizonts] = DetectionOfSchizonts(THS, c) %% Extract all sets. sets = {}; + labelizedTHS = mmlabel(THS, mmsedisk(1, '2D', 'OCTAGON')); % We choose a SE which is not a point to fill side-by-side areas. + n = 1; - remainingTHS = THS; - marker = false(size(THS)); while 1 - [i, j] = find(remainingTHS, 1); - if ~isempty(i) - marker(i, j) = 1; - sets{n} = mminfrec(marker, remainingTHS); %#ok % Reconstruction by dilation. - remainingTHS = remainingTHS & ~sets{n}; - n = n + 1; - marker(i, j) = 0; + set = labelizedTHS == n; + if any(any(set)) + sets{n} = set; else break end - end + n = n + 1; + end %% Check the Hausdorff distance between each set combination by dilation. for i = 1:length(sets) diff --git a/src/Main.m b/src/Main.m index f5dd0a4..a7f6ca5 100644 --- a/src/Main.m +++ b/src/Main.m @@ -1,5 +1,6 @@ %% Parameters +delete('../output') mkdir('../output') % Just in case the 'output' directory doesn't exist. % Hue is unusable for '1305121398'/'0001' @@ -7,10 +8,10 @@ mkdir('../output') % Just in case the 'output' directory doesn't exist. % imageFolder = '1307210661'; % 2. % imageFolder = '1401063467'; % 3. % imageFolder = '1405022890'; % 4. -imageFolder = '1409191647'; % 9. -% imageFolder = '1412151257'; % 10. +% imageFolder = '1409191647'; % 9. +imageFolder = '1412151257'; % 10. (Gamma) -imageNumber = '0004'; +imageNumber = 'Gamma-0.8-0002'; scaleFactor = 0.6; @@ -24,10 +25,21 @@ gtResampled = imresize(gt, scaleFactor); imwrite(imgRGBResampled, '../output/imgRGB.png') imwrite(gtResampled, '../output/gt.png') +disp('1) Detection of parasites ...') [THS, c] = DetectionOfParasites(imgRGBResampled); + +disp('2) Detection of white cells ...') [WBC] = DetectionOfWhiteCells(THS, c); -[Shizonts] = DetectionOfSchizonts(THS, c); -infectedRedCells = THS - WBC - Shizonts; -imwrite(infectedRedCells, '../output/infectedRedCells.png') +disp('3) Detection of schizonts ...') +[schizonts] = DetectionOfSchizonts(THS, c); + +disp('Segmentation of red cells ...') +SegmentationOfRedCells(); + +% infectedRedCells = THS - WBC - schizonts; +% imwrite(infectedRedCells, '../output/infectedRedCells.png') + + +disp('Finished') diff --git a/src/SegmentationOfRedCells.m b/src/SegmentationOfRedCells.m index fe6292b..4a86c1b 100644 --- a/src/SegmentationOfRedCells.m +++ b/src/SegmentationOfRedCells.m @@ -1 +1,4 @@ -function \ No newline at end of file +function [] = DetectionOfSchizonts() + + +end \ No newline at end of file -- 2.45.2