def _find_boundaries_subpixel(label_img):
 ndim = label_img.ndim
 max_label = np.iinfo(label_img.dtype).max
 label_img_expanded = np.zeros([((2 * s) - 1) for s in label_img.shape], label_img.dtype)
 pixels = ([slice(None, None, 2)] * ndim)
 label_img_expanded[pixels] = label_img
 edges = np.ones(label_img_expanded.shape, dtype=bool)
 edges[pixels] = False
 label_img_expanded[edges] = max_label
 windows = view_as_windows(np.pad(label_img_expanded, 1, mode='constant', constant_values=0), ((3,) * ndim))
 boundaries = np.zeros_like(edges)
 for index in np.ndindex(label_img_expanded.shape):
  if edges[index]:
   values = np.unique(windows[index].ravel())
   if (len(values) > 2):
    boundaries[index] = True
 return boundaries

def _find_boundaries_subpixel ( label_img ) : ndim = label_img . ndim max_label = np . iinfo ( label_img . dtype ) . max label_img_expanded = np . zeros ( [ ( ( 2 * s ) - 1 ) for s in label_img . shape ] , label_img . dtype ) pixels = ( [ slice ( None , None , 2 ) ] * ndim ) label_img_expanded [ pixels ] = label_img edges = np . ones ( label_img_expanded . shape , dtype = bool ) edges [ pixels ] = False label_img_expanded [ edges ] = max_label windows = view_as_windows ( np . pad ( label_img_expanded , 1 , mode = 'constant' , constant_values = 0 ) , ( ( 3 , ) * ndim ) ) boundaries = np . zeros_like ( edges ) for index in np . ndindex ( label_img_expanded . shape ) : if edges [ index ] : values = np . unique ( windows [ index ] . ravel ( ) ) if ( len ( values ) > 2 ) : boundaries [ index ] = True return boundaries
see find_boundaries .