Just try below steps
Create Mask Image:- First you need to create a mask image for the leaf, you need to do thresholding, find contour(largest), draw contour(with filled) etc...also for removing edge effect you need to erode your mask, which will give better result.
The below code snippets will do the above
Mat thr;
Mat src=imread("image2.png",1); //Your processed image
cvtColor(src,thr,CV_BGR2GRAY);
threshold(thr,thr,180,255,THRESH_BINARY_INV);
vector< vector <Point> > contours; // Vector for storing contour
vector< Vec4i > hierarchy;
int largest_contour_index=0;
int largest_area=0;
Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image
findContours( thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
{
double a=contourArea( contours[i],false); // Find the area of contour
if(a>largest_area){
largest_area=a;
largest_contour_index=i; //Store the index of largest contour
}
}
drawContours( mask,contours, largest_contour_index, Scalar(255,255,255),CV_FILLED, 8, hierarchy ); // Draw the largest contour using previously stored index.
int dilation_size = 2;
Mat element = getStructuringElement( MORPH_RECT,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
erode( mask, mask, element );
Extract green region:- Here you should use hsv color space, inrange etc... as mentioned in your question.
Mat HSV,hsv_thr,dst;
cvtColor(src,HSV,CV_BGR2HSV);
inRange(HSV,Scalar(20,10,10),Scalar(90,255,255),hsv_thr);
bitwise_not for above image:- Here you should use the mask created above.
bitwise_not(hsv_thr, dst, mask);
Draw the diseased area:- Here again you need to do find contour draw contour etc...
findContours( dst.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
drawContours( src,contours, i, Scalar(0,0,255),1, 8, hierarchy );
You can improve the result by proper filtering, thresholding use proper hsv range etc... Also the above algorithm consider that your background always white and for other background you need to change the steps for creating mask image.
Hope these helpful...