Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 2017-03-28 23:50:02 -0600

Nbb gravatar image

How to find neighbours of each region ?

After I run the watershed segmentation algorithm on a subset of my actual image, I get the following output image description where the black lines indicate the boundary separating two regions. I also have another Mat that stores the labels of each region i.e. pixels belonging to a region would have a similar label.

I would now like to find the neighbors of each region. In the example below, I would have

A is connected to B and C
B is connected to A and C
C is connected to A and B

In my implementation, when I am at a certain pixel (blue box), I scan the outer ring (orange boxes) to see if there is a change in the label and I update the adjacency list accordingly. The problem is, I am visiting each pixel multiple times and is quite inefficient. And so I was wondering if anyone has any suggestion on how I can initialize this adjacency list in an efficient manner. Note that the neighbors can be 8-connected.

image description