필터 지우기
필터 지우기

how to find the neighbors of a pixel in a binary image

조회 수: 3 (최근 30일)
kmla
kmla 2018년 4월 6일
댓글: Walter Roberson 2018년 4월 8일
I have a binary image i want to determine the 8 neighbors of this pixels.
  댓글 수: 4
Andrew Chen
Andrew Chen 2018년 4월 6일
When you say totally around, do you mean if all 8 surrounding pixels are white or not? What do you want the program to tell you if there are only 5 pixels that are white out of the 8?
kmla
kmla 2018년 4월 6일
yes the all 8 surrounding pixels are white

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 4월 6일
conv2(BinaryImage, [1 1 1; 1 0 1; 1 1 1])
The result of this will be 8 for locations that a completely surrounded by white pixels, and will be 0 for pixels that are completely surrounded by black pixels, and will be in-between for pixels that are partly surrounded.
  댓글 수: 4
kmla
kmla 2018년 4월 8일
I have this part of image
i want to determine if the pixels in the red circle is in the black region or white region
Walter Roberson
Walter Roberson 2018년 4월 8일
Index the is_surrounded_by_white result at the row and column indexes to determine if the pixel is completely surrounded or not.
However, consider that if you were to move the left circle a bit further right, it could end up being on the boundary between white and black.
WWWBBBBB
WWWBBBBB
WWOBBBBB
WWWBBBBB
The circle is intended to be shown positioned on top of a 'W'. It would be "in" the white area as far as 5 of its 8 neighbours are concerned, and I think if asked very few people would say that it is part of the black area.
What result would you like to have output in such a case, where something is not completely surrounded by white or black?
WWWWWW
WWWBWW
WWOWWW
WWWWWW
WWWWWW
Is the O (with 'W' there underneath) in the white region or is the presence of that single black pixel enough to say that the O is outside of the white region?

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by