【发布时间】:2021-10-14 14:15:30
【问题描述】:
有2张图片,需要用python/numpy/OpenCV将它们组合起来显示最终的图像,其中左半部分来自第一张图像,右半部分来自第二张图像。
最终的图像应该被一条指定宽度最大为5像素的白色对角线分割,其中对角线由特定的角度指定,哪一边更靠近左边和右边。
【问题讨论】:
标签: python numpy opencv image-processing
有2张图片,需要用python/numpy/OpenCV将它们组合起来显示最终的图像,其中左半部分来自第一张图像,右半部分来自第二张图像。
最终的图像应该被一条指定宽度最大为5像素的白色对角线分割,其中对角线由特定的角度指定,哪一边更靠近左边和右边。
【问题讨论】:
标签: python numpy opencv image-processing
我会这样做:
from matplotlib import pyplot as plt
from skimage.transform import rescale
import numpy as np
img0 = plt.imread('example01.jpeg')
img1 = plt.imread('example02.jpeg')
scale = img1.shape[0]/img0.shape[0]
img0_rescaled = (rescale(img0, [scale, scale, 1])[:, :img1.shape[1], :]*255).astype(np.uint8)
combined = np.ones_like(img1)*255
angle = -np.pi/2.5
lower_intersection = 0.5
line_width = 50
y, x, _ = img1.shape
yy, xx = np.mgrid[:y, :x]
img0_positions = (xx-lower_intersection*x)*np.tan(angle)-line_width//2>(yy-y)
img1_positions = (xx-lower_intersection*x)*np.tan(angle)+line_width//2<(yy-y)
combined[img0_positions] = img0_rescaled[img0_positions]
combined[img1_positions] = img1[img1_positions]
【讨论】: