Outline polygon with square region

조회 수: 6 (최근 30일)
Shane
Shane 2015년 8월 11일
댓글: Shane 2015년 8월 12일
I have a polygon image(mask, 0's and 1's).
Let us pretend it is a octagon of width 200 pixels in a 500x500 pixel image. I want to draw a bounding box around the octagon, however, I want the bounding box to only be made up of 90 degree angles.
Another way to imagine the problem is, take a polygon and put it on a checkerboard. The sub-squares of the checkerboard that has the polygon in it gets a value of 1, and the squares that does not gets a value of 0.
Any ideas on how to easily do this?

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 11일
left = find(any(TheMask,1), 1, 'first');
right = find(any(TheMask,1), 1, 'last');
top = find(any(TheMask,2), 1, 'first');
bottom = find(any(TheMask,2), 1, 'last');
These are going to be in pixels.
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 8월 11일
The only way that I can see a difference between what you ask and poly2mask() is if you want the checkerboard to be lower resolution (larger grained) than that.
If you do have a bitmask generated by a polygon and you want to lower its resolution, then blockproc:
set_if_any = @(blockstruct) ones(size(blockstruct.data),class(blockstruct.data)) * any(blockstruct.data(:));
grainsize = 6; %if you want the new boxes to be 6 x 6
grainedMask = blockproc(ExistingMask, grainsize, set_if_any);
Shane
Shane 2015년 8월 12일
Thanks! That is exactly the type of function I was looking for!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by