Info

此问题已关闭。 请重新打开它进行编辑或回答。

error in kmeans?

1 次查看(过去 30 天)
tan yuki
tan yuki 2016-4-5
关闭: Walter Roberson 2016-4-5
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)

回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by