import numpy as np
from scipy import ndimage


def erode_value_blobs(array, steps=1, values_to_ignore=tuple(), new_value=0):
    unique_values = list(np.unique(array))
    all_entries_to_keep = np.zeros(shape=array.shape, dtype=np.bool)
    for unique_value in unique_values:
        entries_of_this_value = array == unique_value
        if unique_value in values_to_ignore:
            all_entries_to_keep = np.logical_or(entries_of_this_value, all_entries_to_keep)
        else:
            eroded_unique_indicator = ndimage.binary_erosion(entries_of_this_value, iterations=steps)
            all_entries_to_keep = np.logical_or(eroded_unique_indicator, all_entries_to_keep)
    result = array * all_entries_to_keep
    if new_value != 0:
        eroded_entries = np.logical_not(all_entries_to_keep)
        new_values = new_value * eroded_entries
        result += new_values
    return result

[((194, 236), 'numpy.zeros', 'np.zeros', ([], {'shape': 'array.shape', 'dtype': 'np.bool'}), '(shape=array.shape, dtype=np.bool)\n', (202, 236), True, 'import numpy as np\n'), ((150, 166), 'numpy.unique', 'np.unique', (['array'], {}), '(array)\n', (159, 166), True, 'import numpy as np\n'), ((766, 801), 'numpy.logical_not', 'np.logical_not', (['all_entries_to_keep'], {}), '(all_entries_to_keep)\n', (780, 801), True, 'import numpy as np\n'), ((409, 466), 'numpy.logical_or', 'np.logical_or', (['entries_of_this_value', 'all_entries_to_keep'], {}), '(entries_of_this_value, all_entries_to_keep)\n', (422, 466), True, 'import numpy as np\n'), ((519, 582), 'scipy.ndimage.binary_erosion', 'ndimage.binary_erosion', (['entries_of_this_value'], {'iterations': 'steps'}), '(entries_of_this_value, iterations=steps)\n', (541, 582), False, 'from scipy import ndimage\n'), ((617, 676), 'numpy.logical_or', 'np.logical_or', (['eroded_unique_indicator', 'all_entries_to_keep'], {}), '(eroded_unique_indicator, all_entries_to_keep)\n', (630, 676), True, 'import numpy as np\n')]