How can I find the center of mass

23 views (last 30 days)
Anil Cem ALMASULU
Anil Cem ALMASULU on 15 Mar 2020
Commented: Anil Cem ALMASULU on 16 Mar 2020
How can I find center of mass of a frame? I need to find the speed of first and second frame with using center of mass and time. These are frames:

Answers (1)

Image Analyst
Image Analyst on 15 Mar 2020
Edited: Image Analyst on 15 Mar 2020
Use regionprops():
props = regionprops(mask, grayImage, 'WeightedCentroid');
xCOM = props.WeightedCentroid(1)
yCOM = props.WeightedCentroid(2)
If you want the unweighted centroid (unweighted by the gray scale image's values), use 'Centroid' instead of 'WeightedCentroid'.
To get the speed, take the delta x and y and use sqrt() to find the distance between and then divide by the time difference between the frames
distance = sqrt(x2-x1)^2 + (y2-y1)^2);
speed = distance / deltaTime;
  3 Comments
Image Analyst
Image Analyst on 16 Mar 2020
Did it throw an error? regionprops() is in the Image Processing Toolbox and is one of the main functions of that toolbox. Type
>> ver
to see if you have that toolbox.
Anil Cem ALMASULU
Anil Cem ALMASULU on 16 Mar 2020
I could not set up Image Processing Toolbox .I mean ı dont know how to set up Image Processing Toolbox and how to run. When I write your code I get "Unrecognized function or variable 'mask'." error.Like that

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!