gpt4 book ai didi

python - OpenCV 中的 PIL ImageChops.screen

转载 作者:行者123 更新时间:2023-11-28 18:14:57 27 4
gpt4 key购买 nike

如何在 OpenCV 中从 PIL 编写相同的代码

img3 = ImageChops.screen(im1, im2)

最佳答案

您可以使用 ImageChops.screen 使用的公式来实现它:

out = MAX - ((MAX - image1) * (MAX - image2) / MAX) (source)

代码:

import cv2
import numpy as np

im1 = cv2.imread('im1.png').astype(np.uint16)
im2 = cv2.imread('im2.png').astype(np.uint16)

im3 = (255 - ((255 - im1) * (255 - im2) / 255)).astype(np.uint8)

cv2.imwrite('im3.png', im3)

晋升到uint16 s 是必需的,因为两个 uint18 相乘值,最后我将其重新转换为 uint8 s 因为值保证为 < 256再次。

关于python - OpenCV 中的 PIL ImageChops.screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48905676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com