python图片横向合并_python – PIL:复合/合并两个图像为“道奇”

如何使用PIL实现相当于将“闪避”模式中的图层与另一图层合并(如Gimp / Photoshop中所做的那样)?

我有原始图像以及我想用作合并图层的图像,但我不知道怎么做道奇合并/复合:

from PIL import Image, ImageFilter, ImageOps

img = Image.open(fname)

img_blur = img.filter(ImageFilter.BLUR)

img_blur_invert = ImageOps.invert(img_blur)

# Now "dodge" merge img_blur_invert on top of img

最佳答案 可能有一种纯PIL方式来做到这一点;我不知道.但是,如果没有,这是一种你可以用numpy做的方法:

import numpy as np

import Image

import ImageFilter

def dodge(front,back):

# The formula comes from http://www.adobe.com/devnet/pdf/pdfs/blend_modes.pdf

result=back*256.0/(256.0-front)

result[result>255]=255

result[front==255]=255

return result.astype('uint8')

img = Image.open(fname,'r').convert('RGB')

arr = np.asarray(img)

img_blur = img.filter(ImageFilter.BLUR)

blur = np.asarray(img_blur)

result=dodge(front=blur, back=arr)

result = Image.fromarray(result, 'RGB')

result.show()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值