Superpixels that located in the image boundary can be specified manually using appropriate index (such as the following example for the second superpixel, L==2):
In some cases it is needed to specify all of those superpixels located in the image boundary in an systematic and non-manual way, something similar to the image below:
Is there any standard method to do that?



Given the labeled image
L,are all pixels along the left and right edges, and
are all pixels along the top and bottom edges. We can find all labels that touch the image edge by taking the unique values in those to sets: