Error when trying to create a loop for k-means
조회 수: 3(최근 30일)
표시 이전 댓글
Hi all,
I'm trying to loop for a given value of k for a k-means segmentation. The following is the documentation code:
mask1 = pixelLabels==1;
cluster1 = img .*uint8(mask1);
imshow(cluster1)
title ('Objects in Cluster 1');
mask2 = pixelLabels==2;
cluster2 = img .* uint8(mask2);
imshow(cluster2)
title('Objects in Cluster 2');
mask3 = pixelLabels==3;
cluster3 = img .* uint8(mask3);
imshow(cluster3)
title('Objects in Cluster 3');
And this is my attempt at turning it into a loop:
imshow(pixelLabels,[])
title('Image Labeled by Cluster Index');
for i = 1 : k
maskID = strcat('mask', k);
clusterID = strcat('cluster', k);
maskID = pixelLabels == k
clusterID = img.*uint8(maskID);
imshow(clusterID)
title('Objects in Cluster ', num2str(clusterID));
end
I not only get an error (incorrect number of arguments) but I also get an incorrect output (only 1 black image).
Any help would be much appreciated!
댓글 수: 0
채택된 답변
KALYAN ACHARJYA
2020년 1월 22일
편집: KALYAN ACHARJYA
2020년 1월 22일
%Defined
img=
pixelLabels=
k=
for i = 1 : k
maskID = strcat('mask', 1);
clusterID = strcat('cluster', 1);
maskID = pixelLabels == k
clusterID = img.*uint8(maskID);
imshow(clusterID)
title(['Objects in Cluster ',num2str(i)]);
end
댓글 수: 2
KALYAN ACHARJYA
2020년 1월 22일
편집: KALYAN ACHARJYA
2020년 1월 22일
%Defined
img=
pixelLabels=
k=
for i = 1 : k
maskID = strcat('mask', 1);
clusterID = strcat('cluster', 1);
maskID = pixelLabels == k
clusterID = img.*uint8(maskID);
figure,imshow(clusterID); % Figure here
title(['Objects in Cluster ',num2str(i)]);
end
추가 답변(0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!