How to find neighbour pixels of a central pixel in a binary image?

4 次查看(过去 30 天)
I am working on a binary image so how to find its neighbours. I have successfully found neighbour pixels in gray scale image but after its conversion from gray to binary its not giving me the pixels of binary image, its still showing me the pixels of gray scale image. Can anyone provide help on this?
Thanks in advance.
  2 个评论
tauseef ahmad
tauseef ahmad 2017-2-8
hi, Ekta sharma, how you found neighbour pixel in gray image? can you send me the code at tauseefmmd@gmail.com
kmla
kmla 2018-4-6
Hi Ekta Sharma, are you find the code to find neighbors pixels of a central pixel in a binary image? can you send it to me houdakhmila@gmail.com

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2016-1-29
What do you need to do with the neighbours? Do you specifically need to know their indices? If so then in what order?
If you are doing a calculation such as region finding then you would normally use regionprops() or one of the image morphological operators.
If you are doing a calculation such as mean you would normally use conv2()
If you are doing a calculation such as local min or local max then one of the morphological operators can handle that.
If you are doing more complex arithmetic calculations on a block centered around the pixel then nlfilt()
  3 个评论
Walter Roberson
Walter Roberson 2017-2-8
To find the neighbouring pixels for each non-zero pixel in a grayscale image:
[nr, nc] = size(YourImage);
[r, c] = find(YourImage);
aboves = [r - 1, c];
aboves(r == 1, :) = [];
belows = [r + 1, c];
belows(c == nr, :) = [];
lefts = [r, c - 1];
lefts(c == 1, :) = [];
rights = [r, c + 1];
rights(c == nc, :) = [];
aboveleft = [r - 1, c - 1];
aboveleft(r == 1 | c == 1, :) = [];
aboveright = [r, c + 1];
aboveright(r == 1 | c == nc, :) = [];
belowleft = [r + 1, c - 1];
belowleft(r == nr | c == 1, :) = [];
belowright = [r + 1, c + 1];
belowright(r == nr | c == nc, :) = [];
neighbors = [aboveright; lefts; belows; aboveleft; belowright; aboves; rights; belowleft];
Now, neighbors will be two columns, each row of which is the row and column number of a pixel that is a neighbor of a non-zero pixel in the grayscale image. Pixels might occur up to 8 times in the list, due to being neighbors of different non-zero pixels.
Good luck doing anything useful with this list.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by