zoukankan      html  css  js  c++  java
  • 用pillow和 opencv做透明通道的两图混全(blend)

    from PIL import Image as image 
    
    foreground = image.open("donkey.png")
    background = image.open( "back.jpg" )
    alpha = image.open( "donkeyAlpha.png" )
    outImage = image.composite( foreground, background, alpha )
    outImage.save( "./pilblend.png" )
    import cv2
    foreground = cv2.imread("donkey.png")
    background = cv2.imread("back.jpg")
    alpha = cv2.imread("donkeyAlpha.png")
    # Convert uint8 to float
    foreground = foreground.astype(float)
    background = background.astype(float)
    # Normalize the alpha mask to keep intensity between 0 and 1
    alpha = alpha.astype(float)/255
    foreground = cv2.multiply(alpha, foreground)
    background = cv2.multiply(1.0 - alpha, background)
    outImage = cv2.add(foreground, background)
    cv2.imwrite( "./cv2blend.png"  ,outImage )
  • 相关阅读:
    安卓-登陆页面的实现
    异常
    实用类
    Hashset
    Map
    LinkedList
    arraylist
    继承
    字符串相关代码
    数组代码
  • 原文地址:https://www.cnblogs.com/diylab/p/9686481.html
Copyright © 2011-2022 走看看