How to compute regions of matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all
Let's say we have the following matrix:
0 0 0 0 0 0
0 1 0 0 0 0
1 1 0 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 0 0
I want to calculate the size of every connected region of 1s and also get the corresponding matrix elements of each region. The size should be computed as (width + heigth) / 2.
In the example the bottom left region would have size (2 + 3) / 2 and the bottom right region would have size (3 + 2) / 2.
Additional to the size of the regions I also want the corresponding entries of the regions, i.e. region 1 has entries (2,2), (3,1), (3,2) and so on.
How can this be done in Matlab?
I'm looking forward for the answers and wish everybody all the best.
댓글 수: 0
채택된 답변
Jos (10584)
2014년 5월 13일
Trivial, provided you have the image processing toolbox. Take a look at BWLABEL and REGIONPROPS
M = [ 0 0 0 0 0 0
0 1 0 0 0 0
1 1 0 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 0 0]
P = regionprops(bwlabel(M),'boundingbox')
The last two values of the field BoudingBox will give you the height and the width of each connected region.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!