File Exchange

image thumbnail

Draw Bounding Box

version 1.0.0.0 (1.46 KB) by Shadab Khan
This function draws bounding boxes around blobs in a binary image.

3 Downloads

Updated 07 Jan 2010

View License

Input is a binary image, and output is another binary image holding the rectangles over the detected blobs. Its not a superimposition of a rectangle over an image.

DRAWBOUNDINGBOX draws the bounding boxes around the blobs in a binary image image is the binary image input supplied by the user. This function extracts the coordinates and dimension values of each blob from stats.BoundingBox structure one by one and draws the rectangle around them. To store an image you can further use IMWRITE function on the output of the function DRAWBOUNDINGBOX. the new image stored will have the rectangles marked over the blobs since it is not a superimposition.

Cite As

Shadab Khan (2020). Draw Bounding Box (https://www.mathworks.com/matlabcentral/fileexchange/26296-draw-bounding-box), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (15)

prakash dhandhukiya

if sir you are helping in matlan contect me on prakashdhandhukiya@ymail.com

Jack Sparrow

Sir,
I am getting error if I use this code to draw bounding box

"Attempted to access g(0,0); index must be a positive integer

g(y1,i) = 1;

There is an error there

sindhu bijjal

im getting error as
Undefined function or method 'bounding' for input arguments
of type 'char'.
plz help..

Siddarth

plz send code to draw bounding boxes around text lines.......

nausheen

my program is running but i m not getting a rectangle on the region i want blobs

RaviTeja

@YANNICK : Thanks! Itz working.. but how do I see the output ?

danitop

Yannick

Handy submission, but not very well documented and a little inaccurate. For example, should the inner or the outer boundary of the blobs be drawn? Also, the outline is off by one on the top and left edges:

A = [0 0 0 0 0 0; 0 0 1 1 0 0; 0 1 1 1 1 0; 0 0 1 1 0 0; 0 0 0 0 0 0]
B = drawboundingbox(A)

A =

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

>> B = drawboundingbox(A)

B =

1 1 1 1 1 0
1 0 1 1 1 0
1 1 1 1 1 0
1 1 1 1 1 0
0 0 0 0 0 0

This can be fixed by replacing some floor by ceil (4 times, 2 in the lower loop limits, 2 in the loop body) and by changing lines 18 and 20 to this:

g(y1 + stats(k).BoundingBox(4) - 1, i) = 1;
g(j, x1 + stats(k).BoundingBox(3) - 1) = 1;

Jorge Lewinnek

Hi, I like this code, but can you do it without for?, it takes a lot of time to work.

nurul

Hi,

I'm also getting error.

''Undefined function or method 'bounding' for input arguments of type 'char'''.

Can anyone help me???

Naeem Nematollahi

Thanks a lot for your code

Uni A

Hello.

I am getting an error too. It says:
>> drawboundingbox(Ip)
??? Error using ==> drawboundingbox
Too many input arguments.

Error in ==> drawboundingbox at 11
DRAWBOUNDINGBOX [image1] = bwlabel(image);

Any ideas, please?

sanjay

Sir,
I am getting error if I use this code to draw bounding box

"Attempted to access g(0,0); index must be a positive integer

g(y1,i) = 1;

pls suggest me what to be done

lana

thank you very much for your amazing code

Alisha

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!