1 year ago
#353654
user18628648
find segment neighborhood python
I am using slic() from skimage.segmentation to get labeled segmented image. what I need next is to get some kind of neighborhood map. Meaning I need a list of attached neighbors to each segment. I have also got the boundaries for each segment and list of indices of each boundary pixels (I'm not sure it is necessary) . my idea was then to iterate each boundary pixels and search for neighbors. As I'm using a very over segmented images in order to get a gentle color separation between segments its come out that most image pixels are part of the boundaries and that make it really slow. I'm looking for faster way to get this neighbors map.
slic segmentation and boundaries code:
import numpy as np
from PIL import Image
from skimage.segmentation import slic, mark_boundaries, find_boundaries
img = np.array(Image.open(path))
segments = slic(img, n_segments=3000,compactness=5)
boun = find_boundaries(segments, mode='inner').astype(int)
result = np.array(np.where(bon == 1))
listOfCoordinates= list(zip(result[0], result[1]))
for bb in range (len(listOfCoordinates)):
valu = segments[listOfCoordinates[bb]]
boun[listOfCoordinates[bb]] = valu
python
image-segmentation
nearest-neighbor
boundaries
0 Answers
Your Answer