leaf disease classification using svm

Error in Detect (line 94)
test = feat_disease;
code
clc
close all
%quick way to reset
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
I = imread([pathname,filename]);
I = imresize(I,[256,256]);
figure, imshow(I); title('Query Leaf Image');
%% Image Cropping
I=imcrop(I);
figure, imshow(I); title('Image Cropping');
%% Enhance Contrast
I = imadjust(I,stretchlim(I));
figure, imshow(I);title('Contrast Enhanced');
%% Otsu Segmentation
I_Otsu = imbinarize(I,graythresh(I));
%% Conversion to HIS
I_HIS = rgb2hsi(I);
%% Extract Features^M
% Function call to evaluate features
%[feat_disease seg_img] = EvaluateFeatures(I)
% Color Image Segmentation
% Use of K Means clustering for segmentation
% Convert Image from RGB Color Space to L*a*b* Color Space
% The L*a*b* space consists of a luminosity layer 'L*', chromaticity-layer 'a*' and 'b*'.
% All of the color information is in the 'a*' and 'b*' layers.
cform = makecform('srgb2lab');
%% Apply the colorform
lab_he = applycform(I,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure,imshow(pixel_labels,[]), title('Image Labeled by Cluster Index');
%% Create a blank cell array to store the results.
segmented_images = cell(1,3);
%% Create RGB label using pixel_labels
rgb_label = repmat(pixel_labels,[1,1,3]);
for k = 1:nColors
colors = I;
colors(rgb_label ~= k) = 0;
segmented_images{k} = colors;
end
figure,
subplot(3,1,1);imshow(segmented_images{1});title('Cluster 1'); subplot(3,1,2);imshow(segmented_images{2});title('Cluster 2');
subplot(3,1,3);imshow(segmented_images{3});title('Cluster 3');
% % Feature Extraction
x = inputdlg('Enter the cluster no. containing the ROI only:');
i = str2double(x);
seg_img = segmented_images{i};
% Convert to grayscale if image is RGB
if ndims(seg_img) == 3
img = rgb2gray(seg_img);
end
figure, imshow(img); title('Gray Scale Image');
%% Evaluate the disease affected area
black = imbinarize(seg_img,graythresh(seg_img));
% figure, imshow(black);title('Black & White Image');
m = size(seg_img,1);
n = size(seg_img,2);
zero_image = zeros(m,n);
cc = bwconncomp(seg_img,6);
diseasedata = regionprops(cc,'basic');
A1 = diseasedata.Area;
sprintf('Area of the disease affected region is : %g%',A1)
I_black = imbinarize(I,graythresh(I));
kk = bwconncomp(I,6);
leafdata = regionprops(kk,'basic');
A2 = leafdata.Area;
sprintf(' Total leaf area is : %g%',A2)
Affected_Area = (A1/A2);
if Affected_Area < 1
Affected_Area = Affected_Area+0.15;
end
sprintf('Affected Area is: %g%%',(Affected_Area*100))
%%
% Load All The Features
% load('Training_Data.mat')
sprintf('train data');
% Put the test features into variable 'test'
test = feat_disease;
result = multisvm(Train_Feat,Train_Label,test);
%disp(result);
% Visualize Results
if result == 0
helpdlg(' Alternaria Alternata ');
disp(' Alternaria Alternata ');
elseif result == 1
helpdlg(' Anthracnose ');
disp('Anthracnose');
elseif result == 2
helpdlg(' Bacterial Blight ');
disp(' Bacterial Blight ');
elseif result == 3
helpdlg(' Cercospora Leaf Spot ');
disp('Cercospora Leaf Spot');
elseif result == 4
helpdlg(' Healthy Leaf ');
disp('Healthy Leaf ');
end
%% Evaluate Accuracy^M
load('Accuracy_Data.mat')
Accuracy_Percent= zeros(200,1);
for i = 1:500
data = Train_Feat;
%groups = ismember(Train_Label,1);
groups = ismember(Train_Label,0);
[train,test] = crossvalind('HoldOut',groups);
cp = classperf(groups);
svmStruct = fitcsvm(data(train,:),groups(train),'showplot',false,'kernel_function','linear');
classes = ClassificationSVM(svmStruct,data(test,:),'showplot',false);
classperf(cp,classes,test);
Accuracy = cp.CorrectRate;
Accuracy_Percent(i) = Accuracy.*100;
end
Max_Accuracy = max(Accuracy_Percent);
sprintf('Accuracy of classifier after 500 iterations is: %g%%',Max_Accuracy)

1 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 10 月 4 日
Please provide the requred data file to check the code?

サインインしてコメントする。

回答 (1 件)

kumari p
kumari p 2020 年 10 月 4 日

0 投票

clc
close all
%quick way to reset
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
I = imread([pathname,filename]);
I = imresize(I,[256,256]);
figure, imshow(I); title('Query Leaf Image');
%% Image Cropping
I=imcrop(I);
figure, imshow(I); title('Image Cropping');
%% Enhance Contrast
I = imadjust(I,stretchlim(I));
figure, imshow(I);title('Contrast Enhanced');
%% Otsu Segmentation
I_Otsu = imbinarize(I,graythresh(I));
%% Conversion to HIS
I_HIS = rgb2hsi(I);
%% Extract Features^M
% Function call to evaluate features
%[feat_disease seg_img] = EvaluateFeatures(I)
% Color Image Segmentation
% Use of K Means clustering for segmentation
% Convert Image from RGB Color Space to L*a*b* Color Space
% The L*a*b* space consists of a luminosity layer 'L*', chromaticity-layer 'a*' and 'b*'.
% All of the color information is in the 'a*' and 'b*' layers.
cform = makecform('srgb2lab');
%% Apply the colorform
lab_he = applycform(I,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure,imshow(pixel_labels,[]), title('Image Labeled by Cluster Index');
%% Create a blank cell array to store the results.
segmented_images = cell(1,3);
%% Create RGB label using pixel_labels
rgb_label = repmat(pixel_labels,[1,1,3]);
for k = 1:nColors
colors = I;
colors(rgb_label ~= k) = 0;
segmented_images{k} = colors;
end
figure,
subplot(3,1,1);imshow(segmented_images{1});title('Cluster 1'); subplot(3,1,2);imshow(segmented_images{2});title('Cluster 2');
subplot(3,1,3);imshow(segmented_images{3});title('Cluster 3');
% % Feature Extraction
x = inputdlg('Enter the cluster no. containing the ROI only:');
i = str2double(x);
seg_img = segmented_images{i};
% Convert to grayscale if image is RGB
if ndims(seg_img) == 3
img = rgb2gray(seg_img);
end
figure, imshow(img); title('Gray Scale Image');
%% Evaluate the disease affected area
black = imbinarize(seg_img,graythresh(seg_img));
% figure, imshow(black);title('Black & White Image');
m = size(seg_img,1);
n = size(seg_img,2);
zero_image = zeros(m,n);
cc = bwconncomp(seg_img,6);
diseasedata = regionprops(cc,'basic');
A1 = diseasedata.Area;
sprintf('Area of the disease affected region is : %g%',A1)
I_black = imbinarize(I,graythresh(I));
kk = bwconncomp(I,6);
leafdata = regionprops(kk,'basic');
A2 = leafdata.Area;
sprintf(' Total leaf area is : %g%',A2)
Affected_Area = (A1/A2);
if Affected_Area < 1
Affected_Area = Affected_Area+0.15;
end
sprintf('Affected Area is: %g%%',(Affected_Area*100))
%%
% Load All The Features
% load('Training_Data.mat')
sprintf('train data');
% Put the test features into variable 'test'
test = feat_disease;
result = multisvm(Train_Feat,Train_Label,test);
%disp(result);
% Visualize Results
if result == 0
helpdlg(' Alternaria Alternata ');
disp(' Alternaria Alternata ');
elseif result == 1
helpdlg(' Anthracnose ');
disp('Anthracnose');
elseif result == 2
helpdlg(' Bacterial Blight ');
disp(' Bacterial Blight ');
elseif result == 3
helpdlg(' Cercospora Leaf Spot ');
disp('Cercospora Leaf Spot');
elseif result == 4
helpdlg(' Healthy Leaf ');
disp('Healthy Leaf ');
end
%% Evaluate Accuracy^M
load('Accuracy_Data.mat')
Accuracy_Percent= zeros(200,1);
for i = 1:500
data = Train_Feat;
%groups = ismember(Train_Label,1);
groups = ismember(Train_Label,0);
[train,test] = crossvalind('HoldOut',groups);
cp = classperf(groups);
svmStruct = fitcsvm(data(train,:),groups(train),'showplot',false,'kernel_function','linear');
classes = ClassificationSVM(svmStruct,data(test,:),'showplot',false);
classperf(cp,classes,test);
Accuracy = cp.CorrectRate;
Accuracy_Percent(i) = Accuracy.*100;
end
Max_Accuracy = max(Accuracy_Percent);
sprintf('Accuracy of classifier after 500 iterations is: %g%%',Max_Accuracy)

カテゴリ

ヘルプ センター および File ExchangeAgriculture についてさらに検索

質問済み:

2020 年 10 月 4 日

コメント済み:

2020 年 10 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by