From: Greg Burri Date: Thu, 19 Mar 2015 15:42:32 +0000 (+0100) Subject: Add of MATLAB tests. X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=67471e7dc44204d2847f895228749d9bf236749e;p=malaria.git Add of MATLAB tests. --- 67471e7dc44204d2847f895228749d9bf236749e diff --git a/src/loadImg.m b/src/loadImg.m new file mode 100644 index 0000000..5397aca --- /dev/null +++ b/src/loadImg.m @@ -0,0 +1,10 @@ +function [img, gt] = loadImg(name, num) + + imagesFolder = '../imgs_corrMK'; + groundTruthFolder = '../gt'; + filename = [name, '-', num, '.png']; + + img = imread([imagesFolder, '/', name, '/', filename]); + gt = imread([groundTruthFolder, '/', name, '/', filename]) ./ 255; +end + diff --git a/src/main.m b/src/main.m new file mode 100644 index 0000000..0ba3187 --- /dev/null +++ b/src/main.m @@ -0,0 +1,139 @@ +% Load the image and its ground truth. +imageFolder = '1305121398'; +imageNumber = '0001'; +[img, gt] = loadImg(imageFolder, imageNumber); + +% Resample the image and its ground truth. +img = imresize(img, 0.2); +gt = imresize(img, 0.2); + +% Crop the image (for testing). +% img = img(1:300, 1:300, :); + +% Image properties. +[h, w, d] = size(img); % height, width, depth + +%% To gray. +img = rgb2hsv(img); +imgGray = zeros(h, w); + +for i = 1:h + for j = 1:w + h = img(i, j, 1); + s = img(i, j, 2); + v = img(i, j, 3); + imgGray(i, j) = v; +% +% if (h > 0.861 || h < 0.042) && s > 0.05 && v < 0.85 +% imgGray(i, j) = 255 * v; +% else +% imgGray(i, j) = 0; +% end + end +end + + +%% Normalization. +minimum = min(min(imgGray)); +maximum = max(max(imgGray)); +imgGrayNorm = uint8(255 * (imgGray - minimum) / (maximum - minimum)); + + +%% Morphologic transformation + +% Top-hat transformation (p 673). +% Try to do some shading correction +a = imgGrayNorm - mmopen(imgGrayNorm, mmsedisk(40)); + +% Area opening to flatten the cells. +b = mmareaopen(a, 200); + +% Threshold the image to segment cells. +c = mmcmp(uint8(0), '<=', b, '<=', uint8(45)); + +% Smooth the cells and remove little holes. +d = mmopen(c, mmsedisk(2, '2D', 'OCTAGON')); + +% Distance of each cell pixel to its border. +e1 = mmdist(d, mmsebox, 'EUCLIDEAN'); +e2 = mmregmax(e1); % Regional maxima,default SE is a 3x3 cross. +e = mmdil(e2); % Dilation by a 3x3 cross. + +% Watershed. +f = mmneg(e1); +fs = mmsurf(f); +g = mmcwatershed(f, e, mmsebox); + +% Cell separation. +h = mmintersec(c, mmneg(g)); + +% Removing the cells touching the border and too small cells. +i = mmopen(mmedgeoff(h), mmsedisk(3)); + +% Create the border of each cell. +j = mmgradm(i); + +figure('Position', [100 100 1000 800]) +colormap(gray); + +subplot(2, 2, 1); +imagesc(imgGrayNorm); +title([imageFolder, '-', imageNumber]); + +subplot(2, 2, 2); +imagesc(a); +title('a'); + +subplot(2, 2, 3); +imagesc(b); +title('b'); + +subplot(2, 2, 4); +imagesc(c); +title('c'); + +figure('Position', [100 100 1000 800]) +colormap(gray); + +subplot(2, 2, 1); +imagesc(d); +title('d'); + +subplot(2, 2, 2); +imagesc(mmsurf(e1)); +title('Surface of e1'); + +subplot(2, 2, 3); +imagesc(i); +title('i'); + +subplot(2, 2, 4); +mmshow(imgGrayNorm, j); +title('Original + j'); + + + +% figure('Position', [100 100 1000 800]) +% colormap(gray); +% +% subplot(2, 2, 1); +% imagesc(f); +% title('f'); +% +% subplot(2, 2, 2); +% imagesc(fs); +% title('fs'); + + + + + + +% image(imfuse(img, gt, 'blend')); +% colormap('HSV') +% image(gt); +% colormap([0 0 0; 1 1 1]); + +% disp('Some tests ...'); + +