栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

OpenCV Python中的渐变蒙版混合

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenCV Python中的渐变蒙版混合

因此,主要的问题

(mask/255) * blur + (1-mask/255)*anotherimg
是运算符。他们只在一个频道上工作。下一个问题是使用浮点数来“平滑”。
我将与Alpha通道混合的代码更改为:
1)我将每个通道用于源图像和蒙版
2)执行公式
3)合并通道

def blend_with_mask_matrix(src1, src2, mask):    res_channels = []    for c in range(0, src1.shape[2]):        a = src1[:, :, c]        b = src2[:, :, c]        m = mask[:, :, c]        res = cv.add( cv.multiply(b, cv.divide(np.full_like(m, 255) - m, 255.0, dtype=cv.CV_32F), dtype=cv.CV_32F), cv.multiply(a, cv.divide(m, 255.0, dtype=cv.CV_32F), dtype=cv.CV_32F),dtype=cv.CV_8U)        res_channels += [res]    res = cv.merge(res_channels)    return res

作为渐变蒙版,我只是使用模糊的圆圈。

def blur_image(cv_image, radius, center, gaussian_core, sigma_x):    blurred = cv.GaussianBlur(cv_image, gaussian_core, sigma_x)    circle_not_mask = np.zeros_like(cv_image)    cv.circle(circle_not_mask, center, radius, (255, 255, 255), -1)#Smoothing borders    cv.GaussianBlur(circle_not_mask, (101, 101), 111, dst=circle_not_mask)# Computing    res = blend_with_mask_matrix(cv_image, blurred, circle_not_mask)    return res

结果:

它的工作比没有平滑边界的第一个版本慢一些,但是可以。
结束语。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/645814.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号