-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.m
More file actions
137 lines (117 loc) · 4.21 KB
/
Main.m
File metadata and controls
137 lines (117 loc) · 4.21 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
%% Project Title: Paddy Leaf Disease Detection
clc
close all
clear all
while (1==1)
choice=menu('Paddy Leaf Disease Detection','....... Training........','....... Testing......','........ Close........');
if (choice==1)
%% Image Read
xx = 1;
for k=1:20
I = imread(sprintf('C:/Users/Moshiur Rahman Mohim/Desktop/Final File(mohim)/Train/Train (%d).jpg', k));
I = imresize(I,[1000,260]);
[I3,RGB] = createMask(I);
seg_img = RGB;
img = rgb2gray(seg_img);
glcms = graycomatrix(img);
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
Mean = mean2(seg_img);
Standard_Deviation = std2(seg_img);
Entropy = entropy(seg_img);
RMS = mean2(rms(seg_img));
%Skewness = skewness(img)
Variance = mean2(var(double(seg_img)));
a = sum(double(seg_img(:)));
Smoothness = 1-(1/(1+a));
% Inverse Difference Movement
m = size(seg_img,1);
n = size(seg_img,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = seg_img(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);
ff = [Contrast,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, IDM];
if k==1
Train_Feat = ff;
else
Train_Feat = [Train_Feat;ff];
end
if k<10 && k>1
xx = [xx;1];
elseif k>1
xx = [xx;2];
end
Train_Label = xx.';
Train_Label = transpose(xx);
end
disp('Train Complete');
end
if (choice==2)
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
I = imread([pathname,filename]);
I = imresize(I,[1000,260]);
figure, imshow(I); title('Query Leaf Image');
%% Create Mask Or Segmentation Image
[I3,RGB] = createMask(I);
seg_img = RGB;
figure, imshow(I3); title('BW Image');
figure, imshow(seg_img); title('Segmented Image');
%% Feature Extraction
% Convert to grayscale if image is RGB
img = rgb2gray(seg_img);
%figure, imshow(img); title('Gray Scale Image');
% Create the Gray Level Cooccurance Matrices (GLCMs)
glcms = graycomatrix(img);
% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
Mean = mean2(seg_img);
Standard_Deviation = std2(seg_img);
Entropy = entropy(seg_img);
RMS = mean2(rms(seg_img));
%Skewness = skewness(img)
Variance = mean2(var(double(seg_img)));
a = sum(double(seg_img(:)));
Smoothness = 1-(1/(1+a));
% Inverse Difference Movement
m = size(seg_img,1);
n = size(seg_img,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = seg_img(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);
feat_disease = [Contrast,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, IDM];
%% SVM Classifier
% Load All The Features
%load('Training_Data.mat')
% Put the test features into variable 'test'
test = feat_disease;
result = multisvm(Train_Feat,Train_Label,test);
%disp(result);
%% Visualize Results
if result == 1
helpdlg(' Disease Detect ');
disp(' Disease Detect ');
else
helpdlg(' Disease not Detect ');
disp('Disease not Detect');
end
end
if (choice==3)
close all;
return;
end
end