Skip to content

Instantly share code, notes, and snippets.

@bkj
Created October 18, 2019 15:55
Show Gist options
  • Save bkj/cacafec84b1a5eb5bdfb1da12edad8e4 to your computer and use it in GitHub Desktop.
Save bkj/cacafec84b1a5eb5bdfb1da12edad8e4 to your computer and use it in GitHub Desktop.
def rle2mask(rle, height, width):
rle = [int(xx) for xx in rle.split(' ')]
offsets, runs = rle[0::2], rle[1::2]
tmp = np.zeros(height * width, dtype=np.uint8)
for offset, run in zip(offsets, runs):
tmp[offset:offset + run] = 1
return tmp.reshape(width, height).T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment