Clear Filters
Clear Filters

How to crop the segmented objects?

2 views (last 30 days)
aleena n a
aleena n a on 26 Feb 2022
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
DGM on 26 Feb 2022
Edited: DGM on 26 Feb 2022
I doubt that that edge detection is helping here. You've likely thrown away all the information (color) that can allow you to programmatically identify a foot in the context of similar images. All you're left with now is a not-necessarily-closed boundary line. Unless you want to use your eyeballs to identify which regions are feet, the task of identification is not simple. You might find the edge image useful for some parts of the task, but you might also need to use the original image in order to actually do the segmentation.
Also, when you say you want to draw a line through the second toe(s), can you provide a more formal description of such a line? Is it a line from the tip of the toe to some specific point? Is it just medial line down the middle of the toe?
Similarly, you need a central reference line. Is it just a strictly vertical line in the middle of the image? Is it centered somehow between the feet? Is it corrected for perspective?
aleena n a
aleena n a on 26 Feb 2022
Thank you for replying.
The foot angle and the step width has to be found from an image like below,
This is the task. Please help me.

Sign in to comment.

Answers (1)

Image Analyst
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
hold on;
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.
aleena n a
aleena n a on 1 Mar 2022
Thank you for replying. It has given me a good start.
Image Analyst
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!