如何在 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/