-
Notifications
You must be signed in to change notification settings - Fork 10
/
demo.m
67 lines (53 loc) · 1.93 KB
/
demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% References:
% Duggal, Rahul, et al. "Overlapping cell nuclei segmentation in
% microscopic images using deep belief networks.", Proceedings of the
% Tenth Indian Conference on Computer Vision, Graphics and Image Processing. ACM, 2016.
%
% Copyright (c) 2015, Rahul Duggal
% SBILab
% IIIT-Delhi
clc;
clear all;
close all;
%add all folders and subfolders to search path
addpath(genpath('.'));
%load trained model
load Models\nn_macenko.mat
% set default parameters
verbose = 0;
boxSide = 51;
resize = 1;
%specify images
reference = imread(fullfile('Data','Test_Images','ref.JPG'));
image = double(imresize(imread(fullfile('Data','Test_Images','test_1.jpg')),resize));
%normalize using macenko's method
[ image_normalized ] = Norm(image, reference, 'Macenko', 255, 0.15, 1, 0);
%cluster nucleii
totalTime = tic;
fprintf('started kmeans\n');
tic
mask = onlykmeans(image_normalized, verbose);
mask = bwareaopen(mask,500); %remove connected components with lesser than 500 pixels
fprintf('finished kmeans in %f seconds\n',toc);
%isolate clusters
fprintf('separating clusters\n');
tic;
[clustersbw,isolatedbw] = isolateClusters(image_normalized,mask,verbose);
fprintf('finished separating clusters in %f seconds\n',toc);
%break clusters using deep learning
fprintf('breaking clusters\n');
tic;
clusterImage = rgb2gray(uint8(image .* repmat(clustersbw,[1,1,3])));
[segmentedMask predictData] = predictRidge(clusterImage,boxSide,nn,verbose);
%combine isolated and broken nuclei clusters to obtain segmented image
segmentedMask = bitor(segmentedMask,isolatedbw);
segmentedMask = bwareaopen(segmentedMask,500); %filter cc with less than 500 pixels
segmentedImage = image .* repmat(segmentedMask,[1,1,3]);
fprintf('finished breaking clusters in %f seconds\n',toc);
fprintf('total time %f\n',toc(totalTime));
clearvars -except segmentedImage segmentedMask image
figure();
subplot(1,2,1)
imshow(uint8(image));
subplot(1,2,2);
imshow(uint8(segmentedImage));