MCPcopy Create free account
hub / github.com/DingLei14/WiCoNet / rle_encode

Function rle_encode

utils/utils.py:101–111  ·  view source on GitHub ↗
(mask_image)

Source from the content-addressed store, hash-verified

99
100# credits to https://stackoverflow.com/users/6076729/manuel-lagunas
101def rle_encode(mask_image):
102 pixels = mask_image.flatten()
103 # We avoid issues with '1' at the start or end (at the corners of
104 # the original image) by setting those pixels to '0' explicitly.
105 # We do not expect these to be non-zero for an accurate mask,
106 # so this should not harm the score.
107 pixels[0] = 0
108 pixels[-1] = 0
109 runs = np.where(pixels[1:] != pixels[:-1])[0] + 2
110 runs[1::2] = runs[1::2] - runs[:-1:2]
111 return runs
112
113
114class AverageMeter(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected