Borrar filtros
Borrar filtros

color image segmentation bsed on kmeans and Lab color space

2 visualizaciones (últimos 30 días)
Amina Bhaika
Amina Bhaika el 11 de Jun. de 2012
Comentada: yuvraj singh el 21 de Dic. de 2018
I have used the following code for segmenting a plant image containing predominantly yellow and green colors. It uses k-means in the L* a* b* color space.I basically want to extract the yellow parts of the image and then further process these extracted parts for feature analysis.But each time i run the code i get a different order of the clusters formed by k-means.On further analysis i found that the yellow regions were always returning a higher centroid value than the green regions.So i automated the selection of the required yellow cluster based on maximum centroid value.Can you please tell me the reason why yellow clusters always return higher centroid value than green clusters.
he = imread(TestImagePath);
Orig = he;
figure, imshow(Orig), title('Original Image');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[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]);*BOLD TEXT*
for k = 1:nColors
color = he;
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');
figure, imshow(segmented_images{3}), title('objects in cluster 3');
%disp(cluster_center);
mean_cluster_value = mean(cluster_center,2);
%disp(mean_cluster_value);
[tmp, idx] = sort(mean_cluster_value);
disp(tmp);
YellowRustClusterNum = idx(3);

Respuestas (1)

M@lik Ali
M@lik Ali el 9 de Jul. de 2012
I use this code but i get the error at ??? Error using ==> kmeans Too many input arguments.
Error in ==> Kmeans1 at 21 [cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
Can you please help me..
  2 comentarios
Alvi Syahrin
Alvi Syahrin el 7 de Mayo de 2013
Editada: Alvi Syahrin el 7 de Mayo de 2013
Have you tried to make it like this?
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3)
yuvraj singh
yuvraj singh el 21 de Dic. de 2018
Is there any other toolbox you are using which has the same function named kmeans?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by