How to crop the segmented objects?
3 views (last 30 days)
Show older comments
Commented: Image Analyst on 1 Mar 2022
I have to find the foot angle and step width of foot in an image. Edge detection was done. I got edge of two legs. I have to get crop the two foots and draw the line through center and line through second toe to find the foot angle. I have to do t automatically. Is there any way to segment the exact foot from image and do this. Please help me.
This is the edge detected image. From this I have to segment foot portion only.
Any help will be highly appreciated.
Thanks and regards,
Aleena N A
Image Analyst on 26 Feb 2022
Not hard, unless you do what you did. So don't do that. Some inexperienced person probably told you to do edge detection. For some reason inexperienced image processing people always think that edge detection is the number 1 required first step to do any sort of image analysis whatsoever. Don't listen to them. Edge detection is rarely the best approach.
In this case, you can use the Color Thresholder to export a function that will get the feet. Luckily your videographer made some good decisions: the legs are covered in black, and the floor is white. That means you can use HSV color space and find blobs with high saturation. You can use the Color Thresholder to adjust the values and then export the function, or you can just try a threshold of, say 0.25 and see how that works. Then you can take the two largest blobs since there are known to be two feet. Then you can use regionprops() which will fit an ellipse to the feet and give you the angle of the major axis. Something like
rgbImage = imread(fullFileName);
hsvImage = rgb2hsv(rgbImage);
mask = hsvImage(:, :, 2) > 0.25;
% Take two largest blobs.
mask = bwareafilt(mask, 2);
props = regionprops(mask, 'Orientation', 'MajorAxisLength', 'Centroid')
angles = [props.Orientation]
xy = vertcat(props.Centroid) % Get (x,y) of centroids
footLengths = [props.MajorAxisLength]
% If you want to put a line along the foot at the centroid, use a for loop
for k = 1 : length(props)
xc = xy(k, 1);
yc = xy(k, 2);
% Get endpoints of a line segment
x1 = xc + footLengths(k) * cos(angles(k)) / 2;
x2 = xc - footLengths(k) * cos(angles(k)) / 2;
y1 = yc + footLengths(k) * sin(angles(k)) / 2;
y2 = yc - footLengths(k) * sin(angles(k)) / 2;
plot([x1,x2], [y1,y2], 'b-', 'LineWidth', 4);
This is untested code. Fix any errors. Anyway, it should be a good start.
Image Analyst on 1 Mar 2022
If so, would ou consider clicking the "Accept this answer" link? Or you can wait longer to see if you get any more/better answers.
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!