Я хочу сделать аффинное преобразование, а затем использовать интерполяцию ближайшего соседа, сохраняя одинаковые размеры для входных и выходных изображений. Я использую, например, преобразование масштабирования T = [[2,0,0], [0,2,0], [0,0,1]]. Любая идея, как я могу заполнить черные пиксели с ближайшим соседом? Я попытался дать им минимальное значение интенсивности соседей. Например если у пикселя есть соседи [55,22,44,11,22,55,23,231], я даю ему значение минимальной интенсивности: 11. Но результат не совсем ясен ..
import numpy as np
from matplotlib import pyplot as plt
#Importing the original image and init the output image
img = plt.imread('/home/left/Desktop/computerVision/SET1/brain0030slice150_101x101.png',0)
outImg = np.zeros_like(img)
# Dimensions of the input image and output image (the same dimensions)
(width , height) = (img.shape[0], img.shape[1])
# Initialize the transformation matrix
T = np.array([[2,0,0], [0,2,0], [0,0,1]])
# Make an array with input image (x,y) coordinations and add [0 0 ... 1] row
coords = np.indices((width, height), 'uint8').reshape(2, -1)
coords = np.vstack((coords, np.zeros(coords.shape[1], 'uint8')))
output = T @ coords
# Arrays of x and y coordinations of the output image within the image dimensions
x_array, y_array = output[0] ,output[1]
indices = np.where((x_array >= 0) & (x_array < width) & (y_array >= 0) & (y_array < height))
# Final coordinations of the output image
fx, fy = x_array[indices], y_array[indices]
# Final output image after the affine transformation
outImg[fx, fy] = img[fx, fy]
Входное изображение:

Выходное изображение после масштабирования:
