code: def relabel(image):
      
      #
      # Build a label table that converts an old label # into
      # labels using the new numbering scheme
      #
      unique_labels = np.unique(image[image!=0])
      if len(unique_labels) == 0:
          return (image,0)
      consecutive_labels = np.arange(len(unique_labels))+1
      label_table = np.zeros(unique_labels.max()+1, int)
      label_table[unique_labels] = consecutive_labels
      #
      # Use the label table to remap all of the labels
      #
      new_image = label_table[image]
      return (new_image,len(unique_labels))
docs: Given a labeled image, relabel each of the objects consecutively
      
      image - a labeled 2-d integer array
      returns - (labeled image, object count)