Reputation: 192
I'm currently working on a version of SLIC (Simple Linear Iterative Clustering) in Python and I already have the pixels of each superpixel in a list of tuples:
pixels_of_a_superpixel = [(1,2),(3,2),(5,7),...]
I want to compute some metrics (more specifically, compactness) where I need to know the pixels that belong to the border of the superpixel so I can divide this number by the total number of pixels in that region, but I'm not sure how to proceed.
A more general way to visualize what I'm trying to do is by looking at the image below, which is not of the problem I have, but illustrates really well my objective. I already have a list of the pixel position of all the 0s on the image, but I want to extract only the position of the 0s on the boundary of the two regions.
Upvotes: 0
Views: 236
Reputation: 145
If I understand it right, you would like to obtain the index of pixels on the boundary. You can firstly dilate the image with a small structure element, then subtract the original image from the dilated image (dilate(I) - I). You can use the binary_dilation function from scikit-image to do the dilation.
Upvotes: 0