display values in a loop

14 visualizaciones (últimos 30 días)
Shi Wei Foo
Shi Wei Foo el 5 de Dic. de 2011
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 comentarios
David Young
David Young el 5 de Dic. de 2011
What is the problem with the code you have? I tried your suggested call to disp and it seems to work fine.
Shi Wei Foo
Shi Wei Foo el 5 de Dic. de 2011
I'm not sure on that as well. been cracking my head for this. was the syntax wrong?

Iniciar sesión para comentar.

Respuesta aceptada

Chandra Kurniawan
Chandra Kurniawan el 5 de Dic. de 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 comentarios
Chandra Kurniawan
Chandra Kurniawan el 5 de Dic. de 2011
Note : Detected objects only for 1000 < stat.area < 10000
Hope this will helps you
Shi Wei Foo
Shi Wei Foo el 5 de Dic. de 2011
thank you so much it works fine!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by