How to get the x and y coordinates of the each marker in a frame?
2 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/456579/image.jpeg)
0 个评论
采纳的回答
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 个评论
更多回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!