matlab aggregate bounding box area in an image -


i have image i, , set of bounding box positions in matrix a, a=[x10 y10 x11 y11; x20 y20 x21 y21...xn0 yn0 xn1 yn1]. boxes can visualized on image below.

                  imshow(i);                   numparts = floor(size(a, 2)/4);                   = 1:numparts                     x1 = a(1,1+(i-1)*4);                     y1 = a(1,2+(i-1)*4);                     x2 = a(1,3+(i-1)*4);                     y2 = a(1,4+(i-1)*4);                     line([x1 x1 x2 x2 x1]',[y1 y2 y2 y1 y1]','color',colorset{i},'linewidth',2);                   end 

how can aggregate bounding box areas, pixels in boxes labeled 1, otherwise labeled 0? don't want all-inclusive bounding box includes bounding boxes in a. need more precise area map aggregates bounding boxes in a.enter image description here

if understand correctly, want find outer perimeter of of bounding boxes placed together, set entire interior of shape 1. i'm going assume array structured such each row, first 2 co-ordinates top left corner while next 2 co-ordinates bottom right corner of particular bounding box.

what can create binary image , draw each filled bounding box binary image. obtain shape contains of bounding boxes entire interior set 1. such, like:

%// declare mask mask = false(size(i,1), size(i,2));  %// go through each bounding box pair of co-ordinates , draw bounding box %// inside mask %// directly using code... though can more efficiently numparts = floor(size(a, 2)/4); = 1:numparts     x1 = floor(a(1,1+(i-1)*4));     y1 = floor(a(1,2+(i-1)*4));     x2 = floor(a(1,3+(i-1)*4));     y2 = floor(a(1,4+(i-1)*4));      %// draw bounding box here     mask(y1:y2,x1:x2) = true; end  %// show original image mask beside figure; subplot(1,2,1); imshow(i); subplot(1,2,2); imshow(final_mask); 

final_mask should contain seeking. assumption i'm taking here x horizontal while y vertical. if not case, swap first , second dimension indexing in final statement of for loop suit purposes.

take special note took floor of each (x,y) co-ordinate because i'm not sure whether or not have these locations floating point or integer. able use did, must make sure co-ordinates integer able index mask i'm trying make.

also, code not provide error checking. if of bounding boxes go outside of image boundaries, matlab generate error informing of fact. i'll leave additional error checking on drawing bounding box in mask outside of image boundaries. if you're not worried this, don't have code step.

i've written code display original image aggregation mask beside in 1 window.

good luck!


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -