Replace specific rectangular regions with ones

조회 수: 1 (최근 30일)
Elysi Cochin
Elysi Cochin 2021년 7월 7일
댓글: Elysi Cochin 2021년 7월 9일
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;
end
figure, imshow(mask);
  댓글 수: 3
Ben McMahon
Ben McMahon 2021년 7월 7일
편집: Ben McMahon 2021년 7월 7일
Your loop is currently only setting the counter to the final value. To loop over all i in a set use the : notation. For example:
for i = 1:length(bbox)
mask( bbox(i,1) : bbox(i,3) , bbox(i,2) : bbox(i,4) ) = 1;
end
Elysi Cochin
Elysi Cochin 2021년 7월 9일
yes, thank you sir

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

채택된 답변

KSSV
KSSV 2021년 7월 7일
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;
end
figure, imshow(mask);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by