filtered_array[area_mask[id_regions]] = 0
return filtered_array
filtered_array = filter_isolated_cells(square, struct=np.ones((3, 3)))
plt.imshow(filtered_array, cmap=plt.cm.gray, interpolation='nearest')
Removing completely isolated cells from Python array?