bounding box around canny edge detecter
Show older comments
i have detected edges using canny edge detecter now i want to make a bounding box around the object to detect it how can i do that i have used the below code to make a bounding box but it just changes the color of the edges not making a bounding box
if true
% %this program will make a yellow clour on edges
% [B,L] = bwboundaries(F, 'noholes');
% figure; imshow(F); hold on;
% for k = 1:length(B),
% boundary = B{k};
% plot(boundary(:,2),boundary(:,1),'w','LineWidth',2);
% end
end
1 Comment
ahmed SHAH
on 27 Nov 2016
Answers (1)
Image Analyst
on 25 Nov 2016
To get bounding boxes, you'll either have to use regionprops, or use max and min on the x and y vectors:
x = boundary(:,2);
y = boundary(:,1);
x1 = min(x);
x2 = max(x);
y1 = min(y);
y2 = max(y);
xBox = [x1, x2, x2, x1, x1];
yBox = [y1, y1, y2, y2, y1];
% Plot boundary
plot(x, y, 'm-', 'LineWidth' ,2);
% Plot bounding box.
hold on;
plot(xBox, yBox, 'y-', 'LineWidth' ,2);
2 Comments
ahmed SHAH
on 27 Nov 2016
Edited: Image Analyst
on 27 Nov 2016
Image Analyst
on 27 Nov 2016
Edited: Image Analyst
on 27 Nov 2016
Evidently you have some edges out there at the boundary of the image. You'll need to get rid of those. Maybe it's because you, for some reason, inverted the edge image before computing boundaries. I never would have done that. Attach your original image so I can try it. By the way, why even do edge detection? Can't you get the object by simple thresholding?
Categories
Find more on Object Analysis 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!