【问题标题】:Python/Numpy/OpenCV merging 2 images by showing one next to the other separated by a diagonal line [closed]Python / Numpy / OpenCV通过显示一个并排显示由对角线分隔的另一个图像来合并2个图像[关闭]
【发布时间】:2021-10-14 14:15:30
【问题描述】:

有2张图片,需要用python/numpy/OpenCV将它们组合起来显示最终的图像,其中左半部分来自第一张图像,右半部分来自第二张图像。

最终的图像应该被一条指定宽度最大为5像素的白色对角线分割,其中对角线由特定的角度指定,哪一边更靠近左边和右边。

示例: Example merging 2 images

【问题讨论】:

标签: python numpy opencv image-processing


【解决方案1】:

我会这样做:

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]

output example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    相关资源
    最近更新 更多