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

[((7, 26, 7, 68), 'numpy.zeros', 'np.zeros', (), '', True, 'import numpy as np\n'), ((6, 25, 6, 41), 'numpy.unique', 'np.unique', ({(6, 35, 6, 40): 'array'}, {}), '(array)', True, 'import numpy as np\n'), ((17, 25, 17, 60), 'numpy.logical_not', 'np.logical_not', ({(17, 40, 17, 59): 'all_entries_to_keep'}, {}), '(all_entries_to_keep)', True, 'import numpy as np\n'), ((11, 34, 11, 91), 'numpy.logical_or', 'np.logical_or', ({(11, 48, 11, 69): 'entries_of_this_value', (11, 71, 11, 90): 'all_entries_to_keep'}, {}), '(entries_of_this_value, all_entries_to_keep)', True, 'import numpy as np\n'), ((13, 38, 13, 101), 'scipy.ndimage.binary_erosion', 'ndimage.binary_erosion', (), '', False, 'from scipy import ndimage\n'), ((14, 34, 14, 93), 'numpy.logical_or', 'np.logical_or', ({(14, 48, 14, 71): 'eroded_unique_indicator', (14, 73, 14, 92): 'all_entries_to_keep'}, {}), '(eroded_unique_indicator, all_entries_to_keep)', True, 'import numpy as np\n')]