File Exchange

image thumbnail

Plant Leaf Disease Detection and Classification using Multiclass SVM Classifier

version (884 KB) by Manu BN
A Matlab code to detect and classfy diseases in plant leaves using a multiclass SVM classifier


Updated 23 Feb 2016

View License

A Matlab code is written to classify the leaves into one of the following types: 'Alternaria Alternata', 'Anthracnose', 'Bacterial Blight', 'Cercospora Leaf Spot' and 'Healthy Leaves'. Classification is done by Multiclass SVM (one vs. all)
How to run??
1. Place the folder 'Leaf_Disease_Detection_code' in the Matlab path, and add all the subfolders into that path
2. Run DetectDisease_GUI.m
3. In the GUI click on Load Image and load the image from Manu's Disease Dataset, click Enhance Contrast.
4. Next click on Segment Image, then enter the cluster no containing the ROI, i.e only the disease affected part or the healthy part
5. Click on classification results. Then measure accuracy (In this case Healthy vs All diseases).
The code is loosely based on the following paper, please cite the below and give credit to the authors:
[1] Akhtar, Asma, et al. "Automated Plant Disease Analysis (APDA): Performance Comparison of Machine Learning Techniques." Frontiers of Information Technology (FIT), 2013 11th International Conference on. IEEE, 2013.
[2] Multiclass SVM by Anand Mishra link:
Suggestions and comments are always welcome

Thanks in advance,

Manu B.N

Cite As

Manu BN (2019). Plant Leaf Disease Detection and Classification using Multiclass SVM Classifier (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (225)

hi would you pls send me the training_dat.mat and accuracy.mat files?
my email id -

hi. would you please send me train file?



I read all the comments at

I wanted to take advantage of your "Project Title: Pomegranate Leaf Disease Detection" title code. I've analyzed the entire code. I want to ask you two questions.

1.Training_Data.mat file contains features for 125 images. Can you share the database with these images?

2. I have no idea about the data of the first 100 rows from 0 "to the last 25 rows 1" from the Accuracy_Data.mat file. Please give us some information about this.

I found an easier way of classifying.... Use the classifierapp, much easier

hi, i have an error in classify, in this code svmStructDisease = svmtrain(diseasefeat,diseasetype);. how to solve it?

hello sir , please help me can i run this code in simulink for standalone application

Perfectly works with matlab2015

hello sir, The same project I'm doing right now......... upto training part i have done bt how to do the testing part i dont know...... will you help me?
and accuracy that you have calculated how it is done?


Sir, will you be able to send me the details of test and train datasets

sir how to do the 3rd step and where can i get the images

install matlab 2015a .
then this problem will be run smoothly.

Mythilie S

please help me sir....

sir while running i am getting this error

Undefined function 'log' for input arguments of type 'uint8'.

Error in entropy (line 47)

please help

On clicking classification results I got an error "Error while evaluating UI control call back" please help me to get the further results

Thanks for uploading this code.
How was the Training_Data.mat file created?

Sir could you please let me know about the MATLAB dataset created for training and testing. Also please share the username and password for the database connection.
Email address :

Where do I get DISEASESET.mat file

@manu sir,please help me sir......................................................

@manu sir,can i use other image enhancement technique is used ?if possible ,how can i do.please help me sir......

hi sir, I would like to as, to train the training_dataset, am I required to do it manually or there is some code that can train the dataset, if yes can show it to me. thanks

Error using svmtrain (line 230)
svmtrain has been removed. Use fitcsvm instead.

Error in multisvm (line 28)
svmStruct = svmtrain(T,newClass);

Error in DetectDisease_GUI>pushbutton6_Callback (line 381)
result = multisvm(Train_Feat,Train_Label,test);

Error in gui_mainfcn (line 95)

Error in DetectDisease_GUI (line 46)
gui_mainfcn(gui_State, varargin{:});

Error in>@(hObject,eventdata)DetectDisease_GUI('pushbutton6_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

the program show above error how to solve this.

Noble kibru

Hello sir, I am working on a similar project and I am a newbie, I want to know how can I use the function "EvaluateFeatures" to get the train value of a different data set? I mean, I want to create a different "training_data" and "accuracy_data". How can I get it.XXXXXXXXX___________________XXXXXXXX, plz send the source code by this e-mail:-

Dear Sir,Code is runing but show warning. How can i remove this warning? my e-mail address is (,please sent me correction code via e-mail) as soon as possible.

Warning: svmtrain will be removed in a future release. Use fitcsvm instead.
> In svmtrain (line 230)
In DetectDisease_GUI>pushbutton5_Callback (line 330)
In gui_mainfcn (line 95)
In DetectDisease_GUI (line 46)
Warning: svmclassify will be removed in a future release. Use the predict method of an object returned by fitcsvm instead.
> In svmclassify (line 47)
In DetectDisease_GUI>pushbutton5_Callback (line 331)
In gui_mainfcn (line 95)
In DetectDisease_GUI (line 46)

ans =

'Accuracy of Linear Kernel is: 77.4194%'

Riddhi Raj

after changing the path and running the gui.
i do not get any result following step 4. ie Next click on Segment Image, then enter the cluster no containing the ROI, i.e only the disease affected part or the healthy part
i do not any output.
please help asap


Undefined function 'pushbutton19_Callback' for input arguments of type 'struct'.

Error in train3>train3_OutputFcn (line 226)
pushbutton19_Callback(hObject, eventdata, handles)

Error in gui_mainfcn (line 265)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);

Error in train3 (line 42)
gui_mainfcn(gui_State, varargin{:});

why this error comes in training set preperation ? i am not able to add more images for training set then error comes

amruta naik

Sir please can you send me training_data.mat and accuracy_data.mat on my mail id ' '. I don't no how to create it sir. Please sir

amruta naik

vivek yadav

good afternoon sir can i know from where you have taken the data set does you have verified from the authorized person that the image is affected by diseases can i get your report or ieee paper pleases mail on my email id


how to build the Training_Data.mat ..pls explain the steps...

Hi Sir!
i am also working on same project plant disease detection web based system. sir i want help i need source code of your project can you send me on my email ( please. i dont know how i do my work.

how to build the Training_Data.mat ..pls expalin the urgent pls sir

safa ashraf

safa ashraf

how to add more disease to it

how to build the Training_Data.mat ..pls expalin the urgent pls my email id

sir, i am getting an error like undefined function / method 'rms' for input of type 'uint8'
RMS = mean2(rms(seg_img);


how to build the Training_Data.mat ..pls expalin the urgent pls my email id


can you plz help me in running this project ?

hello sir,
i understood all your code. butsir i have only one dout.
i know training set is greater than test set. but sir in training set, where from you get the rest of value ? in given set there are less than 25 images.
sir please clear my doubt. if external ask me this question then what answer i will give him?
sir please please please kindly reply me.....please give response as possible as.
thank you

Mohini Sude

can u send me more details about this learn more about email id is
please give response as possible as.
thank you

Hello sir , I am very new in MATLAB. can u help me to do plant diseases based on wether prediction. Where can i get data for this project? and how to do this ? pls help me. my email id

Hello sir,

i am working on same project... i need your help. I have dataset of leaf diseases, how can I use this code for classification of l 9 classes, sir please tell me step by step approach…

Hello I'm a beginner in MATLAB...I need a code that can help detect nitrogen deficiency in crop leaves

jeet vyas

my email id is:

hello sir please reply to my mail
i wanted to know how do u tell that this method is better than the other methods?
do u have any comparitive studies??

kavitha c

kavitha c

Hello sir, how to create a disease data set.could you send me the sample data set copy to my mail,

now i am start learning on matlab


How to build own basebase file .mat
plz help me..... my contact id

Does anyone know how to align in the centroid of one image another one?

Hello! Can you please send me the report?

Chen Xiao

Thanks, program is good. Please add training function.

How to drow confusion matrix in SVM??

Hello sir, thank you very much for the SVM Code, this code very helpful to me in studying classification image using multi svm. I am working on a similar project and I am a newbie, that I want to ask, does this multi svm work on more than 5 classes data? I tried on 60 class data, but why only 1 classification detected? Anyone who can help, thank you in advance

sir can u please mail the report for the source code of image processing based method to assess fish quality and freshness(

Dear Manu B.N!
I am doing the thesis plant diseases recognation and classification using Multi Class SVM and can we calculate confusion matrix for Multi Class SVM ? I have 5 class data
pleases send full code by meail
thank you more


Hello Manu, can you please mail the report for this souce code. (

Sir can u please mail the report for this source code...

Sir can u please mail me the complete paper(

Pooja DJ

Sir can u plz mail me the report and the complete paper( )

Dear sr I have already 5 class of leaf diseases and I prepare my data set ! how to use this preapre data set?


@Manu, while i run your program Train_Feat,Train_Label automatically gets loaded, but when i run program with my Training data.mat, m getting error "Undefined function or variable 'Train_Feat', Train_Label"


% Put the test features into variable 'test'
test = feat_disease;
result = multisvm(Train_Feat,Train_Label,test);

what is Train_Feat and Train_Label in above line, anyone tell me.
m getting error "Undefined function or variable 'Train_Feat', Train_Label"
m getting error "

Thank you @Ganesh Raut ur code work fine I try it . I wonder if u could help me with the accuracy_data please since I want to build it as well and thank you

Hello sir @Ganesh Raut. First of all thanks for your code. But it is showing a error,"Undefined function or variable 'hObject'.". Is there anything I should put into hObject?

Ganesh Raut

Hello sir, I am working on a similar project and I am a newbie, I want to know how can I use the function "EvaluateFeatures" to get the train value of a different data set? I mean, I want to create a different "training_data" and "accuracy_data". How can I get it?
Thank you.

catch ex
Train_Feat = [];
Train_Label = [];

handles.output = hObject;
ss = ones(300,400);
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
I = imread([pathname,filename]);
I = imresize(I,[256,256]);
I2 = imresize(I,[300,400]);
imshow(I2);title('Input Image');
I4 = imadjust(I3,stretchlim(I));
I5 = imresize(I4,[300,400]);
imshow(I5);title(' Contrast Enhanced ');
I =I4;

cform = makecform('srgb2lab');
% Apply the colorform
lab_he = applycform(I,cform);

% Classify the colors in a*b* colorspace using K means clustering.
% Since the image has 3 colors create 3 clusters.
% Measure the distance using Euclidean Distance Metric.
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', ...
%[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);
% Label every pixel in tha image using results from K means
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 of clustering
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;

figure,subplot(2,3,2);imshow(I);title('Original Image'); subplot(2,3,4);imshow(segmented_images{1});title('Cluster 1'); subplot(2,3,5);imshow(segmented_images{2});title('Cluster 2');
subplot(2,3,6);imshow(segmented_images{3});title('Cluster 3');
set(gcf, 'Position', get(0,'Screensize'));
set(gcf, 'name','Segmented by K Means', 'numbertitle','off')
% Feature Extraction
x = inputdlg('Enter the cluster no. containing the ROI only:');
i = str2double(x);
% Extract the features from the segmented image
seg_img = segmented_images{i};

% Convert to grayscale if image is RGB
if ndims(seg_img) == 3
img = rgb2gray(seg_img);
%figure, imshow(img); title('Gray Scale Image');

% Evaluate the disease affected area
black = im2bw(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);
%G = imoverlay(zero_image,seg_img,[1 0 0]);

cc = bwconncomp(seg_img,6);
diseasedata = regionprops(cc,'basic');
A1 = diseasedata.Area;
sprintf('Area of the disease affected region is : %g%',A1);

I_black = im2bw(I,graythresh(I));
kk = bwconncomp(I,6);
leafdata = regionprops(kk,'basic');
A2 = leafdata.Area;
sprintf(' Total leaf area is : %g%',A2);

%Affected_Area = 1-(A1/A2);
Affected_Area = (A1/A2);
if Affected_Area < 0.1
Affected_Area = Affected_Area+0.15;
sprintf('Affected Area is: %g%%',(Affected_Area*100))
Affect = Affected_Area*100;
% Create the Gray Level Cooccurance Matrices (GLCMs)
glcms = graycomatrix(img);

% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
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));
Kurtosis = kurtosis(double(seg_img(:)));
Skewness = skewness(double(seg_img(:)));
% 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;
IDM = double(in_diff);

feat_disease = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM];
I7 = imresize(seg_img,[300,400]);
imshow(I7);title('Segmented ROI');
Label = menu('Select a disesses','1','2','3','4','5','6','7');
db_count = length(Train_Feat) + 1;
db_count = length(Train_Label) + 1;
% Train_Feat(:,db_count1) = feat_disease;
Train_Label(:,db_count) = Label;
ch = menu(sprintf('Database saved',db_count),'Add More','Clear DB','Exit');
if(ch == 1)
pushbutton19_Callback(hObject, eventdata, handles)
elseif(ch == 2)
ch = menu('Are you sure','Yes','No');
if(ch == 1)
Train_Feat = [];
Train_Label = [];

Hello sir, I am working on a similar project and I am a newbie, I want to know how can I use the function "EvaluateFeatures" to get the train value of a different data set? I mean, I want to create a different "training_data" and "accuracy_data". How can I get it?
Thank you.

it is nice ,but I have 5 class for mazie leaf diseases recognation and classification using multi SVM how to use this code pleases inform teh step??

Manu BN

@ ketan: use Matlab 2013. Some GUI functions might have changed in the later version.
Remember, this project was done 3 years ago.
@ Alehegn: Go thro all the comments below

while running this projrct i'm facing error,

function varargout = DetectDisease_GUI(varargin)

Error: Function definitions are not permitted in this context.

help me please
Thank you.

Sir,I have 4 plant leaf diseases classes ,so how divide train and test the data? And how to extract and save the traning features ant test features?

Manu BN

@ Nimrutha: Training set is usualy bigger than test set.
@ Dipali: rms was the function of Matlab 2013. Check the ones for you version. It looks like u dont hv all the necessary toolboxes
@ Abu: go thro all the comments below
Thanks to all for the ratings

Sir, In the image data set, you have around 80 images only. But in the .mat file, there are 125 tuples of features. From which images did you extract the features? And can you please provide me the process of how did you actually extract the features from the images and created the .mat file? Because the values are contradictory when I extracted the features from those images! Please help me with this!

it is giving error on gui file undefined function rms

Prajwala TM

Sir, could you elaborate a little on the H values required for the automatic thresholding after converting the segmented images to HSV color space ? I'm not able to find the required range of H values for the same.

sri sathish

Friends plz send me the MATLAB code for agricultural plant leaf disease detection.

guys i need matlab code for leaf disease detection.......can anyone send it as soon as possible .........

Training_Data.mat is consist of which kind of information ?

amazing project sir what algorithm's did you use to extract the features? and in the segmentation also?
and thank you so much for ur effort

Hello sir,
Thank you very much for the SVM Code... I'm a student and I have a project about an svm classifier to classify ecg signals but my problem I'm beginner just if you can just how to begin to do the svm how can I do mat files (data set) the diseases are the class and the features of the signals are the input(attributes). I have samples of signals but I don't know how to extract feature from signals and put in mat file or I must write them manually?? means what are the steps to do the svm or how can I modify you code to adapt
who can help me please
it to my project :(


Hello sir, your work is amazing, and i am working on a similar project. can i get the whole paper plus the report and the whole source code please.
this is my email

Manu BN

K means is unsupervised, so have to select the cluster no. Hence it is semi automated.
If u want fully automated, set thresholds in YCbCr or HSV space

Can I automate the K mean process? Because i want to run like this:
Res = Detect(IMG)
Res = disease name

I want it to select the affected cluster by it self.

and how can i extract new features and label of new disease ?? Can you please explain a little?

Manu BN

for the existing .mat file (i.e features & labels) do a vertical concatenation with new features and labels of the new diseases , and save all of it in a new .mat file.
I dont have any database than the existing ones

Thanks! And how do i increase number of diseases ? and data set?

Manu BN

Remove all the GUI functions, keep only the code that does actual work.
Then write a function which takes only the path of the image and put rest of the code in the function.The final results of classification is the output of the function. It should look like this:
[disease_type] = detect("Image Path");

How can I increase number of disease ?
and I want to change this code like, it take a image as an input in function e.g.
Detect ("image's path")
and give name of the disease.. how can I do that?

eddy jain

Great Work.

Hello sir, I am working on a similar project. Can you send me the code and paper?
My mail id is

Manu BN

@ danait: same procedure & same concept

hello thanks for your code would you help me how to do it for detection of skin diseases

Manu BN

Emmanuel: Concatenate the IC & ICICM feature vectors and follow the same procedure

@Manu, I appreciate your work. I was wondering if you could help out with an code implementation of the Integrated Color and Intensity Co-occurrence Matrix (ICICM) for feature extraction...Kindly respond

Thank you so much for your great work, Your project helped me a lot. I just want to ask about the accuracy part to make sure i understand it correctly , Is All i have to do is to pick group of images from the original dataset that i will classify into only two classes :healthy vs diseased , then i apply the same feature extraction methods we have done earlier? then I assign labels that are zeros or ones for this new group of features? is that correct?

hello sir, my final project is similar to your project, would you please send the source code to my email?
thank you so much


Manu BN

If you want more no of diseases to add extract features from all of them add a label and do vertical concatenation with the existing feature set and finally save it into a .mat file using save command

and how i can extract feature all those 13 feature and save in excel

sir please help mi my project is similar to your project please inform mi how i can increase number of disease in this project
and how i create mat file for this

Manu BN

@nige: I also dont have the paper
@bakhta: A pop up dialogue box will appear in which you need to enter the value of the cluster i.e 1,2,3 etc


hello, sir, I just read your project. How cool! But so sorry, I cannot find your paper on the IEEE Xplore. So I wonder if you could send the article to me. Here is my Thanks a lot!

hello, thank you for this code
i have a question, how can i show just the cluster containing the desease?

Manu BN

@ Tejas: The paper I lost it. Plz download from Xplore
@ Suyog: create a database of Pomo leaves and use same method of features extraction

Tejas T

Hello sir,Thanks a ton for this.can you please send me the source code and the paper?
Email me at []
Thanks in advance :)

suyog b

What modify we can do with this code to work with Pomegranate fruit disease detection.

you told that mat file contains the features set and the labels of training data. my question is that in Training_Data...Train_Feat(1,1)indicate what types of features like mean,rms,standard division etc and Train_Label(0) indicate what type of plant leaf like Alternaria Alternata,Anthracnose,Bacterial Blight,etc ..please some one give me answer

Manu BN

Go thro all the comments below, you will find the answer

Hi sir , you have done a great job,can you tell about the Training_data and Accuracy_data
& where did you get these datasets

Manu BN

The method of feature extraction is same as the one mentioned here. After having extracted the features assign label i.e 1 ,2 etc for different types. Store them using a save command. Next while in testing phase once again use the same method of feature extraction. Then apply SVM Train and SVM classify commands and visualize the results.
Thanks for the rating.
If you have any more doubts you can always ask.

please someone give me suggestion that how can i train my new plant leaf diseases. there have any matlab code that i can use for this program and i can run this program for my new diseases leaf.

sir,i am from bangladesh and my project is related to your project.
you have done a great job ,would you like to give me the paper plus the report and the whole source code please.
and another problem i was run this code but some part of the code not working.
please sir help me.

Nice project

Hi sir , you have done a great job , can i get the whole paper plus the report and the whole source code please.
this is my email

Manu BN

Thanks for the rating, the papaer you have to download from IEEE xplore. I somehow lost it.

Hello sir, that is exactly what i am looking for. Your project is awesome, can you please send me the source code and where can I find the paper?
Email me at []
Thanks in advance :)

Hello sir, that is exactly what i am looking for. Your project is awesome, can you please send me the source code and where can I find the paper?
Email me at []
Thanks in advance :)

good project

Manu BN

use one vs all approach. i.e class 1 contains healthy features and class 2 contains the fused features of all the diseases mentioned.
Thanks for the rating.

Hello, Can you tell me how are you calculating the accuracy?

Moh Moh

It is good project. Thanks to author.

Manu BN

Thanks,i have lost the paper somehow, plz download it from IEEE Xplore.

Hi sir , your work is amazing , can i get the whole paper plus the report and the whole source code please.
this is my email

Hello, my thesis is required to get a software that can detect a plant disease. Can i get the whole paper and whole source code ? Please email me Thank you Sir :)

Manu BN

Sure, give me your e mail id

Seth Lfc

Hello Sir can i get the whole paper plus the report and the whole source code please.

peijin wang

sir can you please mail me the paper @ [] thanku sir

priya y

Sir thankyou for your reply.
I have used regionprops method to calculate major and minor axis lengths.But i am getting wrong values using that method when compared distance value using imtool method.So sir please provide solution for this problem.
Thank you in advance.
I have attached image to your mail-id.

Manu BN

@ Tejaswi: Use feed forward NN, use the same feature set but re arrange the rows and columns as necessary. Usually one hidden layer with 10 neurons is sufficent, if not increase the hidden layers to 2. Plenty of tutorials are available on net.
@ Dolly: Set the num of iterations to 1000 thats it. Go thro Matlab documentations in detail.
@Luu: Learn the basics of machine learning, you will understand what is train feat and test feat.
@Pinto: Why convert to grayscale when k means can directly operate on any dimension data???
@ Priya: Yes u can. All you hv to do is a bit of search on net to get the code.

K Tejaswi

My project is also similar to your project but I want to use neural network for training and after doing the training I want to do the testing on the trained network.Can you help me how to save the features extracted in the network and test on those features.

dolly karak

sir can you please tell me how we take 1000 iteration for k-mean using matlab command.

dolly karak

sir can you please mail me the paper @ []
thanku sir

Luu Thanh

dear Sir, Could you please expland about evaluate Accuracy. I don't understand about Train_Feat and Train_Label. Why Train_Label only include value "0" or "1" ? And Train_Feat is featureVector from TestSet ?
Thank sir !

Loyce Pinto

Sir, for the rgb to gray scale conversion for this particular problem is luminous method better or the averaging or the inbuilt function to get more accurate values?

Luu Thanh

@Priya, as Pawan comment, plz using imBinary instead of B. BR !

it is "imBinary" instead of 'B' as reffered in tat code.!!

priya y

I am getting this error,
Undefined function or variable 'B'.

test = regionprops('table',B,{'Area','Centroid','BoundingBox',
'ConvexArea', 'ConvexHull', 'ConvexImage', 'Eccentricity',
'EquivDiameter', 'EulerNumber', 'Extent', 'Extrema'
,'FilledArea','FilledImag ..});
Please help me to come out of this error.

sir! is there any other methods for dynamically select the ROI ie., defected cluster among 3 clusters??????!! during k-means clustering.

priya y

ty @Luu Thanh

Luu Thanh

hello @Priya Y, After research, I found that We can use regionprops to find some feature as your comment. Plz check bellow code :

imBinary = im2bw(imgSeg);
test = regionprops('table',B,{'Area','Centroid','BoundingBox', 'ConvexArea', 'ConvexHull', 'ConvexImage', 'Eccentricity', 'EquivDiameter', 'EulerNumber', 'Extent', 'Extrema' ,'FilledArea','FilledImage' ,'Image', 'MajorAxisLength','MinorAxisLength','Orientation','Perimeter','PixelIdxList','PixelList','Solidity','SubarrayIdx'});

A = test.Area;
E = test.Eccentricity;

BestRegard !

Luu Thanh

Sir, I have a same question with Priya Y, Can I find some Shape feature by regionprops ? thank sir !

priya y

Sir,can i find out eccentricity,solidity,perimeter,bounding box features using regionprops?

Manu BN

Sure, try with any type of NN, or even with KNN or many other classifiers available. Compare accuracies of each.

@ Manu BN,how about using neural network approach?????for classification.

Manu BN

Yes it is likely to happen. Since the query image class is not defined in the training set the svm classifier tries to find the nearest possible match and assigns the label of the most likely class. You see a real time implementation of such a prj should only be done in a specific region for a specific crop for a specific set of diseases dominant in that region for that crop.
Guess you got the point!!!

hii @ Manu BN
i am doing my final year project similar to yours classification,.but i am getting wrong results ie,.if i give input image not comming under my 4 classification then it is giving any one classification which is wrong.please sir can u help me in this????

Manu BN

This is a semi automatic approach I have already said. Go thro the comments below.

Luu Thanh

Thank Sir, Step choose right cluster after K-mean is not good for auto classification. User have to choose. There are any solution for this case ?

Manu BN

Yes, Training_data = [F1;F2;....;Fn];
Label = 1 to n. Where n is the number of classes. Save 'Filename'

Luu Thanh

thank sir, so I have to extract features of each image in TrainingSet and write to '.mat' files ?

Manu BN

Use save command in Matlab. There are plenty of resources in net regarding creation of training set.

Luu Thanh

Dear Sir, I have a question. How to make "mat" files (Training_Data and Accuracy_Data) ? There are any code to make them ? or we have to fill directly ? Thanks !

Manu BN

Go thro all the comments below, you will find the answer.

Loyce Pinto

can you tell me the right method using which we can select a proper feature set as I searched online but haven't found a proper answer! can you tell me how you selected these 13 features??

Manu BN

Search in the net, it is there in many sites.

priya y

Sir, Can u please provide d code for ostu thresholding method?

Manu BN

Try with Otsu and manual thresholding. But the results wont be as good as k means. Yes, this is a semi automatic approach.

Loyce Pinto

Is there anyway to automate the segmentation process? as K means does require human interaction.
Thank You

priya y

Sir,my guide is telling to not to apply k-means clustering for image segmentation because it involves human intervention in choosing the cluster no.,so he asked me to do extract only the diseases part using other techniques.
Please help me with this sir.Provide solutions for this problem sir please.Please tell me which other methods can be used.

priya y

Thank you sir for your suggestion.
sir which is better to use "switch" or "if else-if"?

Manu BN

Training set is always bigger than the test set. Go through the basics of SVM for in depth understanding.

priya y

Thank you sir for your reply.
Sir,in your dataset there are only 15 images for healthy leaves,but in train_feat and train_label .mat file there are 25 values for healthy leaves. How is this possible as we have to take only 1 value for 1 image in .mat file?
Please give me idea regarding this.

Ravi holkar

Manu BN

Extract features only from disease affected part

priya y

Ya sir i have followed d same procedure as u said and i have trained d multisvm classifier with code as u have given,but then too it is showing wrong class.Sir can we use this code for 60 classes?
Sir in .mat file do i have to collect only the diseased part cluster features or all the cluster features?Please provide solution for this.

Manu BN

Train the classifier with the no. of classes and assign a label. Save it using save 'filename' command.

priya y

Yes sir, the code is working properly for dataset which u have attached here.But i am working on other datasets consisting of 60 classes.what changes i have to do to get the correct output.

Manu BN

Read the description properly. It works only on the classes mentioned here.
The code is working perfectly.

priya y

Sir, i am not getting correct output.It is showing the same class for other class of disease also.Please provide a solution for this.

priya y

Can we use this code to classify 60 classes?

priya y

Thank you sir for your reply.Sir do we have to collect features of only diseased part segment or features of all the segments created using k-means clustering.

Manu BN

Once you convert an RGB image into grayscale, the color information will be completely lost. There are algorithms which try to restore the color but you will never get back the original image.
Smootheness is a texture based feature. Go thro GLCM features(Gray Level CoOccurance Matrices) for detailed explanation.

priya y

Sir,i have to prepare d report for this project,i am not getting what content to write for features "smooothness(with standard formula)" and "RMS(with standard formula)".Can u give me this information?

priya y

Thank you sir for reply.If not the direct way then what is the other way to convert gray image back to rgb.

Manu BN

@ Priya: No direct way to convert gray to RGB
@John: Texture based ones also are implemented. Learn about GLCMs(Gray Level Co Occurance Matrices)
For human disease go thro as many papers as possible to build a feature set that gives more than 90% accuracy.Do plenty of trial n error until you get the results.

John Daber

Thanks for your reply. I understand how you collected the statistical feature vectors, but not the texture based ones. Is it implemented in this project?
Well, I'm attempting this on human diseases so I realize the same approach may not work. Still, this has helped a lot.

priya y

Sir,i have collected images of diseased leaves using camera.Then I hv used wiener2() to remove noise from the images.For the sake of using wiener i need to convert images from rgb2gray. But now i am not getting how to convert back images from gray to RGB.I have tried with this code,but getting error
function [Image]=gray2rgb(Image)
%Gives a grayscale image an extra dimension
%in order to use color within it
[m n]=size(Image);
Sir,give solutions for this problem.

Manu BN

@ dolly: Spend some time learning the basics of machine learning. you will get it then.

dolly karak

what is the difference between testing and training data matrix.

Manu BN

@ John: Statistical+Texture are the most popular features for palnt disease and brain tumor.
Go thro various papers on plant diseases and build a feature set that give an accuracy of 90% or above. Do pleant of trial and error. Use DWT2 features also.
The method in link dosn't consider feature extraction but rather considers the whole image as a feature set and assigns label to it.A 100% accuracy in the first run itself is strange (Even I fell for it during my student days!!)

Manu BN

@priya:deconvwnr is the inbuilt command for weiner filtering. Why do you want to deblur the images in the first place when there is no noise in it???

John Daber

Appreciate your efforts. Can I ask why/how you selected these feature vectors? [Contrast,Correlation,Energy...etc]. I'm trying a similar project but with a different data set and these feature vectors are very unreliable for me. I have trained my classifier with around 20 training images and my accuracy is at around 40%. On the other hand, I followed a different approach seen here: which gives me an accuracy of 100%. From what I understand, this tutorial uses the entire image in 'double' in the SVM classifier. As a beginner I'm not sure if that is a correct approach (even though it gives me 100% accuracy) and I'd appreciate your thoughts on that.

priya y

can u tell me how to remove noise in images using wiener filter(matlab code).

dolly karak

sir, as you said 0-4 are the labels assigned to the corresponding 5 classes considered but why did you take only 0 and 1 as lebel in train_level matrix.

Manu BN

arrange features in rows and give labels to each class and finally save it using 'save' command.

How the labels are assign to the features

Manu BN

0-4 are the labels assigned to the corresponding 5 classes considered

dolly karak

last question sir, in the matrix 125*1 named Train_level why you take only 0 and 1 as an element of matrix.

Manu BN

It was directly written in .mat file.

To write to .xls use the code below:
for k=1:size(f,1)

dolly karak

1 more question sir, did you also take training images in excel sheet. actually i don't know how to make database for training. so sir can you please help me to come out from this.
thanku sir.

dolly karak

Thanku sir, Do you first wrote feature set and labels of training data in excel sheet and then convert it in .mat file. can you please send me excel sheet as its shortcut is inside the zip file.

Manu BN

@dolly: .mat file contains the features set and the labels of training data. The accuracy is evaluated for heavthy vs all diseases.

dolly karak

sir can you please tell me why you take .mat file and what is inside the .mat file and can you send me the excel sheet of training_data and accuracy_data on my mail id "".
thanku sir....

split range

Manu BN

@ John: The features set is feat_disease = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM]; A mixture of statistical and texture based features are used.
I have used the images from net to train them. The real time classification should be done for a specific region and for a specific set of diseases dominant in that particular region.
Plz go thro the basic version of this code (Link:
Thanks for the rating.

John Daber

Appreciate your work! Can I know a little more about the training dataset? For example how many images were used for that? (In the hundreds or thousands?) And what feature vectors were selected for it? I'm still new to this field and this has helped me a lot. Thanks.

Manu BN

Other than those images provided I dont have anymore.

priya y

Thank you sir for the paper.Sir can u please send some images of leaf infected taken in digital camera.

Manu BN

@ AK: use winzip or winrar to extract and follow the instructions to run


i downloaded code..but not able extract files...

priya y

Thankyou sir for your answer.

Manu BN

Evaluate each feature from the segmented image and put them in an array. Features = [feature1,2......13];

Give me your e mail id will mail the paper.

Thanks for the rating.

priya y

Sir,can u please attach the paper referred(mentioned above)?I tried downloading but its not accessible.
Thank you

priya y

Sir,how do we have to find out the feature values?

priya y

Thank you very much sir.


A reference paper is added

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux