Outlining an object in an image in MATLAB

geodavegeodave Arizona
edited August 2009 in Science & Tech
Hello All,

I've been working on this for a while now. I'm trying to determine the 2D center of mass of an object from a photograph in MATLAB. Here's the workflow that I've designed so far:

(1) Load the image in MATLAB.
(2) Click out the outline of the object using the "impoly" function.
(3) Compute the area of the resulting polygon.
(4) Compute the center of mass of this polygon and plot it on the original image.

Here's the MATLAB code I have so far:
[php]% Load and display the image:
image = imread('photograph.jpg'); imshow(image);

% Select the outline of the object of interest:
h = impoly(gca,[]);

% Compute area of polygon made by this outline.
% Compute the centroid the polygon.[/php]Here's what I'm trying to figure out:
The "impoly" function in line 4 of the above code allows the user to either copy the xy coordinates of the outline nodes or set the color of the polygon by right clicking in the outlined polygon and selecting an option from the context menu. What I'd like to do is retrieve the coordinates of the nodes without having to select "Copy" from the context menu. This way I'll have the outline of the polygon to compute its area and centroid.

Does anyone have any idea how this can be done (if possible at all)?

Thank you for your time!

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited August 2009
    I think if you say:
    pos = getPosition(h);
    
    it will give you the verticies.
  • geodavegeodave Arizona
    edited August 2009
    That worked! Thank you!
Sign In or Register to comment.