zjuJish commited on
Commit
b772857
·
verified ·
1 Parent(s): 4bdd8b3

Upload layer_diff_dataset/mask.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. layer_diff_dataset/mask.py +12 -0
layer_diff_dataset/mask.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read in a image and its mask, save the image with mask
2
+ import cv2
3
+ import numpy as np
4
+ img = cv2.imread('/mnt/workspace/workgroup/yuanpeng/videoedit/datasets/YoutubeVIS/train/JPEGImages/0a7a2514aa/00000.jpg')
5
+ mask = cv2.imread('/mnt/workspace/workgroup/yuanpeng/videoedit/datasets/YoutubeVOS/train/Annotations/0a7a2514aa/00000.png',cv2.IMREAD_GRAYSCALE).clip(0, 1)
6
+ # 转成灰度图片
7
+ # mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
8
+ # 二值化
9
+ # ret,mask=cv2.threshold(mask, 127, 255, cv2.THRESH_BINARY)
10
+ cv2.imwrite('test_mask0.png', mask*255)
11
+ img = img * mask[:, :, np.newaxis]
12
+ cv2.imwrite('test_mask.png', img)