MCPcopy Create free account
hub / github.com/SceneFun3D/scenefun3d / rle_encode

Function rle_encode

eval/functionality_segmentation/eval_utils/rle.py:5–18  ·  view source on GitHub ↗

Encode RLE (Run-length-encode) from 1D binary mask. Args: mask (np.ndarray): 1D binary mask Returns: counts (list): encoded counts RLE

(mask)

Source from the content-addressed store, hash-verified

3
4
5def rle_encode(mask):
6 """Encode RLE (Run-length-encode) from 1D binary mask.
7
8 Args:
9 mask (np.ndarray): 1D binary mask
10 Returns:
11 counts (list): encoded counts RLE
12 """
13 length = mask.shape[0]
14 mask = np.concatenate([[0], mask, [0]])
15 runs = np.where(mask[1:] != mask[:-1])[0] + 1
16 runs[1::2] -= runs[::2]
17 counts = ' '.join(str(x) for x in runs)
18 return counts
19
20
21def rle_decode(counts, length):

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected