欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python給圖像加上mask,并提取mask區(qū)域?qū)嵗?/h1>
 更新時(shí)間:2020年01月19日 11:07:02   作者:xnholiday  
今天小編就為大家分享一篇python給圖像加上mask,并提取mask區(qū)域?qū)嵗?,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

python對(duì)圖像提取mask部分:

代碼:

#coding:utf-8
import os
import cv2
import numpy as np

def add_mask2image_binary(images_path, masks_path, masked_path):
# Add binary masks to images
  for img_item in os.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像素值相加得到結(jié)果
    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區(qū)域?qū)嵗褪切【幏窒斫o大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論