【问题标题】:cv2.resize with Python : what exactly does the interpolation methods?cv2.resize 与 Python :插值方法到底是什么?
【发布时间】:2018-12-14 16:27:17
【问题描述】:

给定一个代表图像的 9x9 矩阵(其条目是 [R, G, B]),我想创建一个大小为 3x3 的新调整大小的图像,每个条目的计算如下:

  1. 将 9x9 矩阵划分为 9 个 3x3 矩阵块

  2. 计算每个 3x3 矩阵块的平均值(按分量)

  3. 使用这些方法创建 3x3 图像。

到目前为止,我已经在 Python 3.6 中使用了 cv2 库

image_blurred = cv2.resize(original_image, (3,3), interpolation=cv2.INTER_AREA)

但我不确定cv2.INTER_AREA 究竟做了什么。

你能给我一些关于这方面的信息吗? (有一些信息here,但没有给出太多细节。)

非常感谢。

【问题讨论】:

    标签: python cv2


    【解决方案1】:

    似乎插值cv2.INTER_AREA 做了这个平均。如果你有兴趣,我在下面写了一个测试。

    import cv2
    import numpy as np
    n = 9
    grid_colors = []
    for _ in range(n):
        column = []
        for _ in range(n):
            colors = []
            for k in range(3):
                colors.append(np.random.randint(256))
            column.append(colors)
        grid_colors.append(column)
    
    moy = []
    for a in range(3):
        col = []
        for b in range(3):
            colors = []
            for c in range(3):
                colors.append(round(sum([grid_colors[i+3*a][j+3*b][c] for i in range(3) for j in range(3)]) / 9))
            col.append(colors)
        moy.append(col)
    
    image_blurred =  cv2.resize(np.array(grid_colors, dtype = np.uint8), (len(grid_colors[0]) // 3, len(grid_colors) // 3), interpolation=cv2.INTER_AREA)
    print("image blurred: ")
    print(image_blurred)
    print("grid_colors: ")
    print(grid_colors)
    

    【讨论】:

      猜你喜欢
      • 2020-03-10
      • 2019-09-11
      • 1970-01-01
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2014-03-26
      • 2023-04-11
      相关资源
      最近更新 更多