k-mean聚类准确率matlab,如何在matlab中使用k-means聚类来获得准确的聚类

我正在做一个植物病害检测项目。我需要从叶子的图像中提取患病部分,但我无法使用k-means准确地分离出患病区域。具体地说,叶子的其余部分在图像上可见,并且病变部分被分割。这是提取患病部位后的原始图像和图像:original image image after separating diseased parts

这是我写的代码

b=imread('12.jpeg');

G=fspecial('gaussian',[200 250],1);

Ig=imfilter(b,G,'same');

figure,imshow(Ig);

conversionform = makecform('srgb2lab');

lab_img = applycform(Ig,conversionform);

figure,imshow(lab_img);

ab = double(lab_img(:,:,2:3));

nrows = size(ab,1);

ncols = size(ab,2);

ab = reshape(ab,nrows*ncols,2);

nColors = 2;

[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');

segmented_images = cell(1,3);

rgb_label = repmat(pixel_labels,[1 1 3]);

for k = 1:nColors

color = lab_img;

color(rgb_label ~= k) = 0;

segmented_images{k} = color;

end

figure, imshow(segmented_images{1}), title('objects in cluster 1');

figure, imshow(segmented_images{2}), title('objects in cluster 2');

e=segmented_images{1};

figure,imshow(e);

conversionform = makecform('lab2srgb');

new_image=applycform(e,conversionform);

figure,imshow(new_image);我想用K均值聚类只提取患病区域。如果有人能帮助我,我将不胜感激。我正在使用matlab 2009a。