import numpy as np
from skimage import measure as ms


def ShuffleLabel(Label):
    """
    Shuffles labels in a label image to improve visualization and enhance
    object boundaries.

    Parameters
    ----------
    Label : array_like
        A label image generated by segmentation methods.

    Returns
    -------
    Shuffled : array_like
        A label image where all values > 0 are randomly shuffled.

    See Also
    --------
    CondenseLabel
    """

    # get list of unique object labels
    Unique = np.unique(Label.flatten())

    # remove background objects (Label == 0)
    Unique = np.delete(Unique, (Unique == 0).nonzero())

    # generate shuffled list of object values
    np.random.shuffle(Unique)

    # initialize output
    Shuffled = np.zeros(Label.shape)

    # get pixel list for each object
    Props = ms.regionprops(Label.astype(np.int))

    # fill in new values
    for i in range(len(Unique)):
        Coords = Props[i].coords
        Shuffled[Coords[:, 0], Coords[:, 1]] = Unique[i]

    return Shuffled

import numpy as np
from skimage import measure as ms


def ShuffleLabel(Label):
    """
    Shuffles labels in a label image to improve visualization and enhance
    object boundaries.

    Parameters
    ----------
    Label : array_like
        A label image generated by segmentation methods.

    Returns
    -------
    Shuffled : array_like
        A label image where all values > 0 are randomly shuffled.

    See Also
    --------
    CondenseLabel
    """

    # get list of unique object labels
    Unique = np.unique(Label.flatten())

    # remove background objects (Label == 0)
    Unique = np.delete(Unique, (Unique == 0).nonzero())

    # generate shuffled list of object values
    np.random.shuffle(Unique)

    # initialize output
    Shuffled = np.zeros(Label.shape, dtype=np.uint32)

    # get pixel list for each object
    Props = ms.regionprops(Label.astype(np.int))

    # fill in new values
    for i in range(len(Unique)):
        Coords = Props[i].coords
        Shuffled[Coords[:, 0], Coords[:, 1]] = Unique[i]

    return Shuffled

Update ShuffleLabel.py