Why isn't matlab drawing the bounding box on my picture?

I followed these commands in tutorial exactly how he did it to draw a bounding box around the main object of a pic but nothing happened for me. The picture looks the same. Will these commands work or not depending on the picture you are using?
>> walk = imread('walkstraight/frame0062.tif');
>> gray_walk = rgb2gray(walk)
>> bw_walk = im2bw(gray_walk, 0.8);
>> bw = ~bw_walk;
>> bw = bwareaopen(bw, 1000);
>> [bwLabel, num] = bwlabel(bw, 8);
>> s = regionprops(bwLabel, 'BoundingBox');
>> imshow(walk);
>> hold on;
>> rectangle('Position', s.BoundingBox)
>> hold off;

답변 (2개)

TADA
TADA 2021년 9월 5일
Without your image its hard to tell, but I tried your code on a couple matlab builtin images and it seems to work.
if you get an error, you may have more than one bounding box returned from regionprops, then you can use a loop to plot all rectangles
imshow(walk);
hold on;
for i = 1:numel(s)
rectangle('Position', s(i).BoundingBox)
end
hold off;
if you don't get an error, but just can't see the rectangle, it may be actually drawn around the entire image. It might happen if the contrast isn't high enough.
in that case, you can try lowering the cutoff intensity you use for im2bw.

댓글 수: 5

No error so the second one. Is there a way I can change the color of the rectangle to see if its working?
rectangle('Position', s(i).BoundingBox, 'EdgeColor', 'r'); % or any other color
What is the (i) for ?
Maybe it's not necessary, it was copied from the loop above
Ok so it works but it's drawing the bounding box around the border/frame of the whole entire image, and not the object of the human walking in the middle of the image.

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

Image Analyst
Image Analyst 2021년 9월 5일
Is the main object the largest one? If so, instead of
bw = bwareaopen(bw, 1000);
do this:
bw = bwareafilt(bw, 1); % Take largest blob only.
Attach your image if you reply to either one of us. And tell us where to find the tutorial you're following.

댓글 수: 4

Just tried it and didn't work. This one: https://www.youtube.com/watch?v=q2hO7p_BqjM
Again, please attach 'walkstraight/frame0062.tif' to avoid any further delay. I would have worked on it now, but now I'm heading out for a while to do some yardwork.
It doesn't let me attach .tif files. I converted it to .jpg - Idk if it will work the same though.
Well you could enclose it in a .zip file. It allows .zip files.

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

카테고리

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

질문:

2021년 9월 5일

댓글:

2021년 9월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by