I have a (big) boolean array and I'm looking for a way to fill True
where it merges two sequences of True
with minimal length.
For example:
a = np.array([True] *3 + [False] + [True] *4 + [False] *2 + [True] *2)
# a == array([ True, True, True, False, True, True, True, True, False, False, True, True])
closed_a = close(a, min_merge_size=2)
# closed_a == array([ True, True, True, True, True, True, True, True, False, False, True, True])
Here the False
value in index [3]
is converted to True
because on both sides it has a sequence of at least 2 True
elements. Conversely, elements [8]
and [9]
remain False
because the don't have such a sequence on both sides.
I tried using scipy.ndimage.binary_closing with structure=[True True False True True]
(and with False
in the middle) but it doesn't give me what I need.
Any ideas?