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

11 ビュー (過去 30 日間)
Anjitha Diva
Anjitha Diva 2020 年 12 月 10 日
コメント済み: Image Analyst 2020 年 12 月 16 日
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
Image Analyst 2020 年 12 月 10 日
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.
mask = bwareafilt(mask, 5);
% Find centroids.
props = regionprops(mask, 'Centroid');
% 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 件のコメント
Anjitha Diva
Anjitha Diva 2020 年 12 月 11 日
編集済み: Anjitha Diva 2020 年 12 月 16 日
Thank you. It worked perfectly when i changed
xy(:, y)
to
xy(:, 2)
in
plot(xy(:, 1), xy(:, y), 'r+', 'LineWidth', 2, 'MarkerSize', 30);
Image Analyst
Image Analyst 2020 年 12 月 16 日
Yep, sorry for the typo.

サインインしてコメントする。

その他の回答 (1 件)

Steve Eddins
Steve Eddins 2020 年 12 月 10 日
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.
RGB = imread('image.jpeg');
% 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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by