-
Notifications
You must be signed in to change notification settings - Fork 0
/
review.m
102 lines (78 loc) · 2.43 KB
/
review.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
clear all;
clc;
close all;
%Get the directory of the images
srcFiles = dir('Dataset/*.jpg');
for i = 1 : length(srcFiles)
img=strcat('Dataset/',srcFiles(i).name);
I = imread(img);
I=imresize(I,[500 500]);
% apply guassian filter
I=rgb2gray(I);
J=imgaussfilt(I,0.5);
% Apply Iterative thresholding
iterthreshold=iter_threshold(J);
%complementing the thresholded image
I=imcomplement(iterthreshold);
%remove the lung border i.e.., the ribcage and muscle
I=imclearborder(I);
%fill the holes of the above image to get PT1
I=imfill(I,'holes');
PT1=I;
%mapping PT1 with input image
I=immultiply(J,I);
%Get the threshold value for thresholding above step image by CLAHE
I=adapthisteq(I);
level = graythresh(I);
I = imbinarize(I,level);
%complement the otsu's thresholded image
I=imcomplement(I);
%PT2 is this image
PT2=I;
%map PT1 and PT2 and fill the holes and remove small connected pixels and
%apply morphological closing to get the ROI
K=immultiply(PT1,PT2);
I=ExtractNLargestBlobs(K,1);
SE=strel('square',2);
I=imclose(I,SE);
I=imfill(I,'holes');
ROI=I;
%This is the segmented image mapped with ROI and original image
I=immultiply(I,J);
%Extract features from the ROI
area=regionprops(ROI,'area');
conv_Area=regionprops(ROI,'ConvexArea');
equi_diameter=regionprops(ROI,'EquivDiameter');
eccentricity=regionprops(ROI,'eccentricity');
solidity=regionprops(ROI,'Solidity');
perimeter=regionprops(ROI,'Perimeter');
standard_deviation=std2(I);
if i<length(srcFiles)
feature(i,:)=[area.Area,conv_Area.ConvexArea,eccentricity.Eccentricity,equi_diameter.EquivDiameter,perimeter.Perimeter,solidity.Solidity,standard_deviation];
if i>5 %modify this
y(i,1)=0; % 0 indicates no pneumothorax
else
y(i,1)=1; % 1 indicates pneumothorax
end
xlswrite('features.xls',[feature]);
else
%Last images in the folder is the test input to test
j=i-length(srcFiles)+1;
sample(j,:)=[area.Area,conv_Area.ConvexArea,eccentricity.Eccentricity,equi_diameter.EquivDiameter,perimeter.Perimeter,solidity.Solidity,standard_deviation];
end
end
%Training model
net = fitnet(10,'trainlm');
net.divideParam.trainRatio=.7;
net.divideParam.valRatio=.15;
net.divideParam.testRatio=.15;
[net, pr]=train(net,feature',y');
%Test with input
output=net(sample')';
output1=round(output,0);
%Determine whether pneumothorax or not
if ((output1<0) || (output1==0))
fprintf('The test CT does not have pneumothorax\n');
else
fprintf('The test CT has pneumothorax\n');
end