display values in a loop
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
David Young
am 5 Dez. 2011
What is the problem with the code you have? I tried your suggested call to disp and it seems to work fine.
Akzeptierte Antwort
Chandra Kurniawan
am 5 Dez. 2011
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 Kommentare
Chandra Kurniawan
am 5 Dez. 2011
Note : Detected objects only for 1000 < stat.area < 10000
Hope this will helps you
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!