how to draw a BoundingBox
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
aziz diallo
am 7 Mai 2018
Kommentiert: Marek Balaz
am 8 Mai 2018
Hello. Can someone help me please ? I'm just starting in programation. I found a code that can detect edges, and i want to draw a bounding boxes arround the detected edges.
if true
close all;clear all;clc
vid = VideoReader ('F:\TRAIT IMG\DETECTION\vol_drone.mp4');
k = vid.NumberOfFrames;
for i=1:k
J=read(vid,i);
%imshow(rgb2gray(J));
%J = imread('drone.jpg');
I = rgb2gray(J);
% imshow(I), title('image original grisé');
[~, threshold] = edge(I, 'sobel');
fudgeFactor = .5;
BWs = edge(I,'sobel', threshold * fudgeFactor);
figure, imshow(BWs), title('binary gradient mask');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = J;
Segout(BWoutline) = 255;
figure,
imshow(Segout), title('outlined original image');
end
end
0 Kommentare
Akzeptierte Antwort
Marek Balaz
am 7 Mai 2018
Bearbeitet: Image Analyst
am 8 Mai 2018
Hello,
I'm not sure in what state are your images after image preprocessing but this is what I used in similar problem with drawing bounding boxes.
imshow(YOUR_IMAGE);
hold on;
labeledImage = logical(YOUR_BINARY_IMAGE); %not needed, image should be already in logical
measurements = regionprops(labeledImage, 'BoundingBox');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position',[thisBB(1),thisBB(2),thisBB(3),thisBB(4)],'EdgeColor','b','LineWidth',1 );
end
2 Kommentare
Image Analyst
am 8 Mai 2018
I think you meant
labeledImage = bwlabel(YOUR_BINARY_IMAGE);
Marek Balaz
am 8 Mai 2018
Hello Image Analyst,
No, I didn't. Here is MATLAB Explanation:
Code Analyzer has found a call of regionprops with a first argument that is a call to bwlabel. In many cases, the argument of bwlabel is a logical matrix, or you can convert it to one. Beginning in MATLAB Version 7.8 (release R2009a), you can pass this logical matrix directly to regionprops without the call to bwlabel. This is faster and uses less space than the previous method.
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!