Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cv2中的PIL ImageCups.screen_Python_Opencv_Image Processing_Python Imaging Library_Cv2 - Fatal编程技术网

Python cv2中的PIL ImageCups.screen

Python cv2中的PIL ImageCups.screen,python,opencv,image-processing,python-imaging-library,cv2,Python,Opencv,Image Processing,Python Imaging Library,Cv2,如何在cv2中使用来自PIL的相同代码 img3 = ImageChops.screen(im1, im2) 您可以使用ImageChops.screen使用的公式来实现它: out=MAX-((MAX-image1)*(MAX-image2)/MAX)() 守则: import cv2 import numpy as np im1 = cv2.imread('im1.png').astype(np.uint16) im2 = cv2.imread('im2.png').astype(np.

如何在cv2中使用来自PIL的相同代码

img3 = ImageChops.screen(im1, im2)

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

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

守则:

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

屏幕将两个倒置的图像叠加在一起()

您也可以这样做(无需
numpy
):

import cv2

# read the input images, they can be color (RGB) images too
im1 = cv2.imread('im1.jpg')
im2 = cv2.imread('im2.jpg')

# images must be of same size, if not resize one of the images 
if im1.shape != im2.shape:
    im2 = cv2.resize(im2, im1.shape[:2][::-1], interpolation = cv2.INTER_AREA)

# invert and normalize first image
im1 = cv2.normalize(cv2.bitwise_not(im1), None, 0, 1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)

# invert and normalize second image
im2 = cv2.normalize(cv2.bitwise_not(im2), None, 0, 1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)

# superimpose two images, re-normalize and invert
im = cv2.bitwise_not(cv2.normalize(cv2.multiply(im1, im2), None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U))

# write the output image
cv2.imwrite('im.jpg', im)