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

 채택된 답변

Marek Balaz
Marek Balaz 2018년 5월 7일
편집: Image Analyst 2018년 5월 8일

1 개 추천

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

I think you meant
labeledImage = bwlabel(YOUR_BINARY_IMAGE);
Marek Balaz
Marek Balaz 2018년 5월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2018년 5월 7일

댓글:

2018년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by