From c9ed8d104a62abf86629a17b4ba89c04019a5036 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 1 May 2015 00:09:44 +0200 Subject: [PATCH] Add the main script and a test script about the hue component. --- src/DetectionOfParasites.m | 4 +--- src/Main.m | 33 ++++++++++++++++++++++++++ src/THue.m | 47 ++++++++++++++++++++++++++++++++++++++ src/loadImg.m | 14 ++++++++++-- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/Main.m create mode 100644 src/THue.m diff --git a/src/DetectionOfParasites.m b/src/DetectionOfParasites.m index 9dca5c4..8d3b2be 100644 --- a/src/DetectionOfParasites.m +++ b/src/DetectionOfParasites.m @@ -5,8 +5,6 @@ % 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); @@ -32,7 +30,7 @@ function [THS, c] = DetectionOfParasites(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')); diff --git a/src/Main.m b/src/Main.m new file mode 100644 index 0000000..f5dd0a4 --- /dev/null +++ b/src/Main.m @@ -0,0 +1,33 @@ +%% 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') + diff --git a/src/THue.m b/src/THue.m new file mode 100644 index 0000000..996f816 --- /dev/null +++ b/src/THue.m @@ -0,0 +1,47 @@ +%% 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 diff --git a/src/loadImg.m b/src/loadImg.m index 1db3a64..c985597 100644 --- a/src/loadImg.m +++ b/src/loadImg.m @@ -1,10 +1,20 @@ +% 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 -- 2.45.2