|
a |
|
b/testingCode.m |
|
|
1 |
% Testing on New Data (capsule endoscopy images) |
|
|
2 |
% Developer: Tonmoy Ghosh (tghosh@crimson.ua.edu) |
|
|
3 |
|
|
|
4 |
clear; close all; clc; |
|
|
5 |
% load trained network |
|
|
6 |
data = load('CEtrainedSegNet.mat'); |
|
|
7 |
net = data.net; |
|
|
8 |
labelIDs = PixelLabelIDs(); |
|
|
9 |
cmap = CEColorMap; |
|
|
10 |
classes = [ |
|
|
11 |
"Bleeding" |
|
|
12 |
"Non_Bleeding" |
|
|
13 |
"Background" |
|
|
14 |
]; |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
imdsTest = imageDatastore('testImage.png'); % image location and name |
|
|
19 |
pxdsTest = pixelLabelDatastore('testLabel.png',classes,labelIDs); |
|
|
20 |
tic |
|
|
21 |
I = read(imdsTest); |
|
|
22 |
I = imresize(I,[256 256]); |
|
|
23 |
C = semanticseg(I, net); |
|
|
24 |
|
|
|
25 |
%Display the results. |
|
|
26 |
B = labeloverlay(I, C, 'Colormap', cmap, 'Transparency',0.4); |
|
|
27 |
figure |
|
|
28 |
imshow(B) |
|
|
29 |
pixelLabelColorbar(cmap, classes); |
|
|
30 |
|
|
|
31 |
L = read(pxdsTest); |
|
|
32 |
expectedResult = imresize(L{1},[256 256],'nearest'); |
|
|
33 |
actual = uint8(C); |
|
|
34 |
expected = uint8(expectedResult); |
|
|
35 |
figure; |
|
|
36 |
imshowpair(actual, expected) |
|
|
37 |
|
|
|
38 |
iou = jaccard(C, expectedResult); |
|
|
39 |
table(classes,iou) |
|
|
40 |
|
|
|
41 |
%Evaluate Trained Network |
|
|
42 |
pxdsResults = semanticseg(imdsTest,net,'WriteLocation',tempdir,'Verbose',false); |
|
|
43 |
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTest,'Verbose',false); |
|
|
44 |
|
|
|
45 |
toc |