bounding box around canny edge detecter

7 ビュー (過去 30 日間)
ahmed SHAH
ahmed SHAH 2016 年 11 月 25 日
編集済み: Image Analyst 2016 年 11 月 27 日
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 件のコメント
ahmed SHAH
ahmed SHAH 2016 年 11 月 27 日
after applying you code nothing happens in image
if true
%
A = imread('shuttle.jpg');
%// Some pre-processing. Treshold image and dilate it.
B = im2bw(A,.85);
%// Detect edges
F = edge(B,'Canny');
% F=~F;
figure;
imshow(F);
hold on;
[B,L] = bwboundaries(F, 'noholes');
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.
figure;
imshow(F);
hold on;
plot(xBox, yBox, 'y-', 'LineWidth' ,2);
end

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 11 月 25 日
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 件のコメント
ahmed SHAH
ahmed SHAH 2016 年 11 月 27 日
編集済み: Image Analyst 2016 年 11 月 27 日
further modiying my own code i get a image with bounding box on left side in image but i want box to be small like its detecting the object in the right pic
% A = imread('shuttle.jpg');
%// Some pre-processing. Treshold image and dilate it.
B = im2bw(A,.85);
%// Detect edges
F = edge(B,'Canny');
F=~F;
figure;
imshow(F);
hold on;
% % 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),'b','LineWidth',2);
end
Image Analyst
Image Analyst 2016 年 11 月 27 日
編集済み: Image Analyst 2016 年 11 月 27 日
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?

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by