简体   繁体   中英

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 :

  1. divide the 9x9 matrix into 9 blocks of 3x3 matrices

  2. compute the mean (component-wise) of each 3x3 matrix bloc

  3. create the 3x3 image with these means.

So far I have used the cv2 library with Python 3.6

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

But I am not sure about what precisely cv2.INTER_AREA does.

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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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