cropping a triangular area determined by two points and a known angle

5 views (last 30 days)
Hi all, so I have an image (frame from a video cropped and resized to 500x500x3). Within that image I have located an object of interest (a bee; always close to the middle [250 250]). I've fitted an ellipse around the bee and get an angle for that ellipse, which tells me the direction she is facing (with the help of a paint mark near her head). I can estimate her 'attentional' field of view to be about 15 degrees on either side of a line pointing in her viewing direction. I'd like to crop her field of view (and do other stuff I can handle with that). I had imagined that I could use poly fit to get the slope of the line, then somehow use the field of view angle to determine the triangle (or pie shape) which I would crop from the image. Any help is appreciated. Cheers, Clint

Accepted Answer

Image Analyst
Image Analyst on 8 Feb 2015
Clint, usually people attach an image if they want image processing advice, so I'm guessing "blind" here. I'd say threshold the bee, or somehow segment it out. Then label it and call regionprops and ask for the "Orientation" (the angle). See my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 if you need help in the basics of image segmentation.
  2 Comments
Image Analyst
Image Analyst on 9 Feb 2015
Edited: Image Analyst on 9 Feb 2015
Regarding your answer, use trigonometry. You know the angle, and you must specify the distance from the bee point. So just calculate the x,y location of the two leg endpoints.
angle1 = angle - 15;
y1 = yBee + distance * sind(angle1);
x1 = xBee + distance * cosd(angle1);
angle2 = angle + 15;
y2 = yBee + distance * sind(angle2);
x2 = xBee + distance * cosd(angle2);
% Get all three in an array
yTriangle = [yBee, y1, y2, yBee];
xTriangle = [xBee, x1, x2, xBee];
mask = poly2mask(xTriangle, yTriangle, rows, columns);
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));
Of course you may need to make sure that x and y are not less than 1 or more than rows or columns, and if they are, clip them so that they aren't outside the image.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!