【问题标题】:How to average the non-zero pixels of two images with slight offset [python]如何平均两个具有轻微偏移的图像的非零像素[python]
【发布时间】:2018-11-03 23:18:29
【问题描述】:

我有两张灰度图像有轻微的偏移(约 80% 重叠),我需要将其平均为一张图像。图像周围有填充,因此图像中已经考虑了重叠(即每个图像的 x 和 y 起始位置不同)。图像以其当前偏移对齐,类似于全景图像。

我目前的方法(见下文)是使用嵌套的 for 循环,比较每个位置的像素强度,将它们相加,然后除以非零计数。

    combined_image=np.empty((image1.shape))
    for row in range(image1.shape[0]):
        for pixel in range(image2.shape[1]):
            temp_array = np.array((image1[row][pixel], image2[row][pixel]))
            combined_image[row][pixel] = np.sum(temp_array)/np.count_nonzero(temp_array)

我相信它可以工作,但是它相当慢,因为这些图像是 1000 x 1000 像素。想知道是否有更有效的方法

【问题讨论】:

    标签: python panoramas


    【解决方案1】:

    通常,如果您在 numpy 中使用 for 循环,则无法利用其内置功能。

    使用广播操作。

    combined_image = (image1 + image2) / 2

    应该更快更简单

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2012-09-23
      相关资源
      最近更新 更多