Info

This question is closed. Reopen it to edit or answer.

error in kmeans?

1 view (last 30 days)
tan yuki
tan yuki on 5 Apr 2016
Closed: Walter Roberson on 5 Apr 2016
i try to apply kmeans on an image but it keeps on error. the coding is as shown below. pls advice.
I=imread('....');
im=rgb2gray(I);
data=double(im(:));
nrows = size(data,1);
ncols = size(data,2);
data = reshape(data,nrows*ncols,1);
[idx,C] = kmeans(data,3)
b=uint8(C==1);
b1=b*255;
figure, imshow(b1),title('Object 1');
L1=bwlabel(b1);
stats = regionprops(L1,'Centroid','Area','BoundingBox');
area1=[stats.Area];
sprintf('area1 = %d', area1)
c=uint8(C==2);
c1=c*255;
figure, imshow(c1),title('Object 2');
L2=bwlabel(c1);
stats2 = regionprops(L2,'Centroid','Area','BoundingBox');
area2=[stats2.Area];
sprintf('area2 = %d', area2)
d=uint8(C==3);
d1=d*255;
figure, imshow(d1),title('Object 3');
L3=bwlabel(d1);
stats3 = regionprops(L3,'Centroid','Area','BoundingBox');
area3=[stats3.Area];
sprintf('area2 = %d', area3)

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!