code: def adjacent(labels):
      '''Return a binary mask of all pixels which are adjacent to a pixel of 
         a different label.
         
      '''
      high = labels.max()+1
      if high > np.iinfo(labels.dtype).max:
          labels = labels.astype(np.int)
      image_with_high_background = labels.copy()
      image_with_high_background[labels == 0] = high
      min_label = scind.minimum_filter(image_with_high_background,
                                       footprint=np.ones((3,3),bool),
                                       mode = 'constant',
                                       cval = high)
      max_label = scind.maximum_filter(labels,
                                       footprint=np.ones((3,3),bool),
                                       mode = 'constant',
                                       cval = 0)
      return (min_label != max_label) & (labels > 0f adjacent(labels):
      '''Return a binary mask of all pixels which are adjacent to a pixel of 
         a different label.
         
      '''
      high = labels.max()+1
      if high > np.iinfo(labels.dtype).max:
          labels = labels.astype(np.int)
      image_with_high_background = labels.copy()
      image_with_high_background[labels == 0] = high
      min_label = scind.minimum_filter(image_with_high_background,
                                       footprint=np.ones((3,3),bool),
                                       mode = 'constant',
                                       cval = high)
      max_label = scind.maximum_filter(labels,
                                       footprint=np.ones((3,3),bool),
                                       mode = 'constant',
                                       cval = 0)
      return (min_label != max_label) & (labels > 0)
docs: Return a binary mask of all pixels which are adjacent to a pixel of 
         a different label.