Replace specific rectangular regions with ones

1 view (last 30 days)
Elysi Cochin
Elysi Cochin on 7 Jul 2021
Commented: Elysi Cochin on 9 Jul 2021
I wanted to fill the rectangular positions in bbox (values attached in order - [x y width height]) with ones.
I tried the below code, but i dont get any white regions, what can be the reason?
mask = zeros(300,950);
load bbox
for i = length(bbox)
mask(bbox(i,1) : bbox(i,3) , bbox(i,2) : bbox(i,4)) = 1;
figure, imshow(mask);

Sign in to comment.

Accepted Answer

KSSV on 7 Jul 2021
mask = zeros(30,95);
load bb.mat
bbox = round(bb) ;
for i = length(bbox)
row1 = ceil(bbox(2));
row2 = row1 + bbox(3);
column1 = ceil(bbox(1));
column2 = column1 + bbox(4);
mask(row1:row2,column1:column2) = 1;
figure, imshow(mask);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!