docs: def table_idx_from_labels(labels):
      '''Return an array of indexes into a morphology lookup table
      labels - a labels matrix
      
      returns a matrix of values between 0 and 511 of indices appropriate
      for table_lookup where a pixel's index is determined based on whether
      or not the pixel has the same label as its neighbors (and is labeled)
      '''
      m=np.zeros((labels.shape[0],labels.shape[1]),int)
      exponent = 0
      for i in range(-1,2):
          ilow = (i==-1 and 1) or 0
          iend = (i==1 and labels.shape[0]-1) or labels.shape[0] 
          for j in range(-1,2):
              jlow = (j==-1 and 1) or 0
              jend = (j==1 and labels.shape[1]-1) or labels.shape[1]
              #
              # Points outside of bounds are different from what's outside,
              # so set untouched points to "different"
              #
              mask = np.zeros(labels.shape, bool)
              mask[ilow:iend, jlow:jend] = (labels[ilow:iend,jlow:jend] == 
                                            labels[ilow+i:iend+i,jlow+j:jend+j])
              m[mask] += 2**exponent
              exponent += 1
      return m