# Kmeans clustering in YUV image space

1 visualizzazione (ultimi 30 giorni)
Algorithms Analyst il 7 Feb 2013
Hi all.
I have a problm in kmeans clustering using matlab.when I apply kmeans function in my image I get following error
Warning:Emty Cluster created at iteration 1.
Warning:Emty Cluster created at iteration 2.
Warning:Emty Cluster created at iteration 3.
Warning:Emty Cluster created at iteration 4.
I am using it becasue I am reducing colors of image and want to get the most representative colors of image. How can I solve this error.y code is under
NoColors=40;
K=40;
[Rows Cols NumberofColors ]=size(image);
s_img=size(image);
inputImg=zeros((s_img(1)*s_img(2)),3);
inputImg(:,2)=U(:);
inputImg(:,3)=V(:);
inputImg=double(inputImg);
%Kmeans starting
[idx C]=kmeans(inputImg,NoColors,'EmptyAction','singleton');
% %Kmeans Completed
palette=round(C);
% %Color Mapping
idx=uint8(idx);
outImg=zeros(s_img(1),s_img(2),3);
temp=reshape(idx,[s_img(1) s_img(2)]);
for i=1:1:s_img(1)
for j=1:1:s_img(2)
outImg(i,j,:)=palette(temp(i,j),:);
end
end
Remember image is in YUV space and just want to quantize the color of UV image.
Thannks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Thorsten il 7 Feb 2013
[idx C]=kmeans([U(:) V(:)],NoColors,'EmptyAction','singleton');
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Color Segmentation in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by