简体   繁体   English

cv2.resize与Python:插值方法到底是什么?

[英]cv2.resize with Python : what exactly does the interpolation methods?

Given a 9x9 matrix representing an image (its entries are a [R, G, B]), I want to create a new resized image with size 3x3 which each entry is computed as follows : 给定一个表示图像的9x9矩阵(其条目为[R,G,B]),我想创建一个尺寸为3x3的新的调整大小的图像,每个条目的计算方式如下:

  1. divide the 9x9 matrix into 9 blocks of 3x3 matrices 将9x9矩阵分成9个3x3矩阵块

  2. compute the mean (component-wise) of each 3x3 matrix bloc 计算每个3x3矩阵块的均值(按分量)

  3. create the 3x3 image with these means. 使用这些方法创建3x3图像。

So far I have used the cv2 library with Python 3.6 到目前为止,我已经在Python 3.6中使用了cv2库

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

But I am not sure about what precisely cv2.INTER_AREA does. 但是我不确定cv2.INTER_AREA是做什么的。

Could you give me some information about this ? 你能给我一些信息吗? (There are some information here but they do not give so many details.) (这里有一些信息但是没有提供太多细节。)

Many thanks. 非常感谢。

It seems that the interpolation cv2.INTER_AREA does this averaging. 似乎插值cv2.INTER_AREA此平均。 I wrote a test below if you are interested. 如果您有兴趣,我在下面写了一个测试。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM