HumanSignal / label-studio-converter

Tools for converting Label Studio annotations into common dataset formats
https://labelstud.io/
262 stars 130 forks source link

mask -> rle problem #66

Closed gezhaoDL closed 3 years ago

gezhaoDL commented 3 years ago

I wrote these lines for mask -> rle,but the length of rle is very long,so the json file was big. What is the correct way to convert mask to rle?

seg= cv2.imread('1.png')
h, w = seg.shape[0], seg.shape[1]
label_img = cv2.cvtColor(seg, cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(label_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
mask_im = np.zeros((h, w, 4))
mask_contours = cv2.drawContours(mask_im, contours, -1, color=(0, 255, 0, 100), thickness=-1)
rle = encode_rle(mask_contours.ravel().astype(int))
print(len(rle))
makseq commented 3 years ago

Please, check this guide: https://labelstud.io/guide/predictions.html#Import-brush-segmentation-pre-annotations-in-RLE-format Hope this helps. However the output RLE will be large, it's ok.

gezhaoDL commented 3 years ago

Please, check this guide: https://labelstud.io/guide/predictions.html#Import-brush-segmentation-pre-annotations-in-RLE-format Hope this helps. However the output RLE will be large, it's ok.

it worked.Thanks