# How to get the x and y coordinates of the each marker in a frame?

15 views (last 30 days)
Anjitha Diva on 10 Dec 2020
Commented: Image Analyst on 16 Dec 2020
I am doing a project on gait analysis, were i have put 5 marker on a person and took the video of him walking. I uploaded this video and i divided it into frames( it was about 111 frames) and also successfully identified the 5 markers(drew boundary with green colour) but i am not able to get the coordinates of each marker. The image after identifying the marker would look something like this.

Image Analyst on 10 Dec 2020
Since the signal seems to be brightest in the green channel, let's just take that channel and get the 5 largest blobs and get their centroids:
% Extract green channel.
greenChannel = rgbImage(:, :, 2);
% Threshold to find the bright blobs.
mask = greenChannel > 128; % or whatever works.
% Extract only the 5 largest blobs.
% Find centroids.
% Extract centroids from structure into a double array.
xy = vertcat(props.Centroid);
% Plot them with a red crosshairs over the image.
hold on;
plot(xy(:, 1), xy(:, y), 'r+', 'LineWidth', 2, 'MarkerSize', 30);
If there might be some dots occluded so that there are only 3 or 4 instead of 5 then replace bwareafilt() by bwareaopen() to filter based on size rather than number.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 16 Dec 2020
Yep, sorry for the typo.

Steve Eddins on 10 Dec 2020
I used the Color Thresholder app to get code that segments your image based on the green color of the markers. Then I used regionprops on the resulting image to get the centroids of each marker.
% Convert RGB image to chosen color space
I = rgb2lab(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 81.590;
% Define thresholds for channel 2 based on histogram settings
channel2Min = -73.999;
channel2Max = 31.677;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 20.187;
channel3Max = 67.712;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
c = regionprops(BW,'Centroid')
c =
5×1 struct array with fields:
Centroid
c.Centroid
ans =
120.9508 146.8361
ans =
131.9130 315.9565
ans =
136.1628 186.8837
ans =
145.7391 268.3043
ans =
145.5517 308.2414

### Community Treasure Hunt

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

Start Hunting!

Translated by