aggregate bounding box area in an image
2 次查看(过去 30 天)
显示 更早的评论
I have an image I, and a set of bounding box positions in a matrix A, A=[x10 y10 x11 y11; x20 y20 x21 y21...xn0 yn0 xn1 yn1]. Those boxes can be visualized on the image like below.
imshow(I);
numparts = floor(size(A, 2)/4);
for i = 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146077/image.jpeg)
How can I aggregate those bounding box areas, so that pixels in the those boxes are labeled as 1, otherwise labeled as 0? I don't want an all-inclusive bounding box which includes all bounding boxes in A. I need a more precise area map which aggregates bounding boxes in A.
0 个评论
回答(1 个)
Image Analyst
2014-11-11
Maybe this:
[rows, columns, numberOfColorChannels] = size(I);
binaryImage = false(rows, columns);
for i = 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);
binaryImage(y1:y2, x1:x2) = true;
end
imshow(binaryImage);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!