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 件のコメント

Image Analyst
Image Analyst 2018 年 5 月 8 日
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 ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by