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