bounding box around canny edge detecter

7 Ansichten (letzte 30 Tage)
ahmed SHAH
ahmed SHAH am 25 Nov. 2016
Bearbeitet: Image Analyst am 27 Nov. 2016
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 Kommentar
ahmed SHAH
ahmed SHAH am 27 Nov. 2016
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 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 Kommentare
ahmed SHAH
ahmed SHAH am 27 Nov. 2016
Bearbeitet: Image Analyst am 27 Nov. 2016
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 am 27 Nov. 2016
Bearbeitet: Image Analyst am 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?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by