python给图像加上mask,并提取mask区域实例
python对图像提取mask部分:
代码:
#coding:utf-8 importos importcv2 importnumpyasnp defadd_mask2image_binary(images_path,masks_path,masked_path): #Addbinarymaskstoimages forimg_iteminos.listdir(images_path): print(img_item) img_path=os.path.join(images_path,img_item) img=cv2.imread(img_path) mask_path=os.path.join(masks_path,img_item[:-4]+'.png')#mask是.png格式的,image是.jpg格式的 mask=cv2.imread(mask_path,cv2.IMREAD_GRAYSCALE)#将彩色mask以二值图像形式读取 masked=cv2.add(img,np.zeros(np.shape(img),dtype=np.uint8),mask=mask)#将image的相素值和mask像素值相加得到结果 cv2.imwrite(os.path.join(masked_path,img_item),masked) images_path='/home/xinan/cat_test/image/' masks_path='/home/xinan/cat_test/catmask/' masked_path='/home/xinan/cat_test/masked/' add_mask2image_binary(images_path,masks_path,masked_path)
效果图:
mask:
image:
result:
以上这篇python给图像加上mask,并提取mask区域实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下