python按钮虚化,深度学习与图像处理实例:人像背景虚化与背景替换

本文介绍了一种使用DeepLabV3模型进行人像背景虚化处理的方法,包括图像分割、背景模糊、人像与模糊背景融合的步骤。通过Python和Tensorflow实现,展示了从原始图像到背景替换的完整过程,尽管还有优化空间。
摘要由CSDN通过智能技术生成

简单人像背景虚化处理思路如下:

对图像内容分割,提取人像,背景

背景模糊处理

人像与模糊处理后的背景融合

本实例使用DeepLabV3图像分割深度学习模型实现。代码如下:

import numpy as np

import tensorflow as tf

import cv2

from deeplabmodel import *

def create_pascal_label_colormap():

colormap = np.zeros((256, 3), dtype=int)

ind = np.arange(256, dtype=int)

for shift in reversed(range(8)):

for channel in range(3):

colormap[:, channel] |= ((ind >> channel) & 1) << shift

ind >>= 3

return colormap

def label_to_color_image(label):

if label.ndim != 2:

raise ValueError('Expect 2-D input label')

colormap = create_pascal_label_colormap()

if np.max(label) >= len(colormap):

raise ValueError('label value too large.')

return colormap[label

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值