% THS: Parasites of all types and WBC (mask).
% c: Typical red cell radius [px].
function [THS, c] = DetectionOfParasites(imgRGB)
-
- imwrite(imgRGB, '../output/imgRGB.png')
%% Extracting of H, S and V components
imgHSV = rgb2hsv(imgRGB);
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'));
--- /dev/null
+%% Parameters
+
+mkdir('../output') % Just in case the 'output' directory doesn't exist.
+
+% Hue is unusable for '1305121398'/'0001'
+% imageFolder = '1305121398'; % 1.
+% imageFolder = '1307210661'; % 2.
+% imageFolder = '1401063467'; % 3.
+% imageFolder = '1405022890'; % 4.
+imageFolder = '1409191647'; % 9.
+% imageFolder = '1412151257'; % 10.
+
+imageNumber = '0004';
+
+scaleFactor = 0.6;
+
+% Load the image and its ground truth.
+[imgRGB, gt] = loadImg(imageFolder, imageNumber);
+
+% Resample the image and its ground truth.
+imgRGBResampled = imresize(imgRGB, scaleFactor);
+gtResampled = imresize(gt, scaleFactor);
+
+imwrite(imgRGBResampled, '../output/imgRGB.png')
+imwrite(gtResampled, '../output/gt.png')
+
+[THS, c] = DetectionOfParasites(imgRGBResampled);
+[WBC] = DetectionOfWhiteCells(THS, c);
+[Shizonts] = DetectionOfSchizonts(THS, c);
+
+infectedRedCells = THS - WBC - Shizonts;
+imwrite(infectedRedCells, '../output/infectedRedCells.png')
+
--- /dev/null
+%% THue.m
+
+%% Init
+clear
+close all
+
+%% Data
+% RGB = imread ('/Users/michel.kocher/michel/Data/Movable/imgs_corrMK/Gamma/1412151257-Gamma-0.8-0002.png');
+
+RGB = imread('../imgs_corrMK/Gamma/1412151257-Gamma-0.8-0002.png');
+
+%% HSV
+HSV = rgb2hsv (RGB);
+H = HSV (:, :, 1);
+S = HSV (:, :, 2);
+Bin = linspace (0, 1, 200);
+[Count] = hist (H(:), Bin);
+
+
+%% Compute by hands of Hue
+
+% Normalized in [0..1]. From : http://en.wikipedia.org/wiki/Hue
+hue = @(r, g, b) atan2(sqrt(3.0) * (g - b), 2.0 * r - g - b) / (2.0 * pi);
+i = 20;
+j = 20;
+r = double(RGB(i,j,1)) / 255 * 2 * pi;
+g = double(RGB(i,j,2)) / 255 * 2 * pi;
+b = double(RGB(i,j,3)) / 255 * 2 * pi;
+fprintf('r: %d, g: %d, b: %d\n', double(RGB(i,j,1)) / 255, double(RGB(i,j,2)) / 255, double(RGB(i,j,3)) / 255);
+fprintf('Hue by hand: %0.5f\n', hue(r, g, b));
+fprintf('Hue by ''rgb2hsv'' : %0.5f\n', H(i, j));
+
+%% Display
+figure('Position', [100 100 1600 800])
+ax (1) = subplot (2, 2, 1);
+imshow (RGB), title ('RGB')
+ax (2) = subplot (2, 2 ,2);
+imshow (H, []), title ('Hue')
+subplot (2, 2, 3)
+bar (Bin, log10(Count+1)), axis square, axis tight, title ('hist(Hue), log space')
+ax (3) = subplot (2, 2, 4);
+imshow (S, []), title ('Saturation')
+
+linkaxes (ax)
+
+%% Print 2 file
+% print ('-f1', '-dpng', 'THue.png')
\ No newline at end of file
+% Load the image and the ground-truth from the given foldername and suffix.
+% If the ground-truth isn't found then it is put to white.
function [img, gt] = loadImg(name, num)
imagesFolder = '../imgs_corrMK';
groundTruthFolder = '../gt';
filename = [name, '-', num, '.png'];
+ filepath_img = [imagesFolder, '/', name, '/', filename];
+ filepath_gt = [groundTruthFolder, '/', name, '/', filename];
- img = imread([imagesFolder, '/', name, '/', filename]);
- gt = imread([groundTruthFolder, '/', name, '/', filename]);
+ img = imread(filepath_img);
+
+ try
+ gt = imread(filepath_gt);
+ catch exception
+ fprintf('Can''t load the ground-truth : %s\n', exception.message)
+ gt = ones(size(img));
+ end
end