Take coordinate data from struct, throw it into an array. Why is this hard to find info about?
    2 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Matthew Powell
 le 16 Fév 2015
  
    
    
    
    
    Modifié(e) : Ashish Uthama
    
 le 17 Fév 2015
            Hi,
I'm working on an image processing program that takes coordinate data of objects in an image acquired via the command regionprops and throws it into an array (that I will grab with a C program).
I'm having no issue sorting singular values into an array, but I am failing to put the coordinate data into one, which looks like [x,y].
code snippet:
blobMeasurements = regionprops(labeledImage, i, 'all');  %labeledImage has object information        
numberOfBlobs = size(blobMeasurements, 1);
Centroid = size(blobMeasurements, ???);
g = 1;
n = 1;
for n = 1:97 
  if (blobMeasurements(n).Area > 500) 
    Centroid(g) = blobMeasurements(n).Centroid;
    g = g + 1;
  end
end
All I need is a simple set of lines that can achieve this. For the record, this isn't a homework assignment.
0 commentaires
Réponse acceptée
  Ashish Uthama
    
 le 17 Fév 2015
        
      Modifié(e) : Ashish Uthama
    
 le 17 Fév 2015
  
      Does this help? (If not, use this example code to show how you want your Centriod variable to look like)
stats = regionprops(im2bw(imread('coins.png')),'all');
%%Indices of 'larger' areas 
% The key here is using [] to capture the output of stats.Area into an
% array.
inds = [stats.Area]>1000;
%%Centroids, using logical indexing
% This gives you the data in [x1 y1 x2 y2 ....] format
centroids = [stats(inds).Centroid];
[EDIT - add table syntax] With the latest version, regionprops now supports tables, making it even more easier:
stats = regionprops('table',im2bw(imread('coins.png')),'all');
inds = stats.Area>100;
centroids = stats.Centroid(inds,:);
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!