display values in a loop
조회 수: 14 (최근 30일)
이전 댓글 표시
i have this code to find all the centroids which objects have the specific area. however, I couldnt find a way to display the values and maybe pass the values to a variable(s). I really appreciate it if somebody could help me with some demos.
below is part of the code:
id = find([s.Area] > 1000 & [s.Area] < 100000 );
for ii = 1:length(id);
hold on, plot(s(id(ii)).Centroid(1),s(id(ii)).Centroid(2),'wp','MarkerSize',10,'MarkerFaceColor','r'), hold off
i want to do something like.. %disp(['Center location is (',num2str(s(id(ii)).Centroid(1),4),', ',num2str(s(id(ii)).Centroid(2),4),')'])
thanks in advance!
댓글 수: 2
David Young
2011년 12월 5일
What is the problem with the code you have? I tried your suggested call to disp and it seems to work fine.
채택된 답변
Chandra Kurniawan
2011년 12월 5일
Hello,
Here I give you my sample code
clear; clc;
I = imread('pillsetc.png');
bw = im2bw(I);
open = bwareaopen(bw,5);
SE = strel('square',5);
close = imclose(open, SE);
fill = imfill(close,'holes');
stat = regionprops(fill,'area','centroid');
id = find([stat.Area] > 1000 & [stat.Area] < 100000 );
imshow(I); hold on;
for x = 1 : length(id)
plot(stat(id(x)).Centroid(1),stat(id(x)).Centroid(2),'ro');
a(x) = stat(id(x)).Centroid(1);
b(x) = stat(id(x)).Centroid(2);
cenText = strcat('Center location is (',num2str(a(x),4),', ',num2str(b(x),4),')');
text(a(x)-80,b(x)+20,cenText,'color','g','fontweight','bold');
disp(cenText);
end
The x-centroid stored in variable 'a' and
the y-centroid stored in variable 'b'
Then both of figure and command window will show you the text that you want to display.
댓글 수: 2
Chandra Kurniawan
2011년 12월 5일
Note : Detected objects only for 1000 < stat.area < 10000
Hope this will helps you
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!