我想调整图片的大小。 我的图片包含特定的值[0、1、2、7、9]。 调整大小后,会引入新值,例如5等。 我想防止这种情况发生。
我目前正在使用scikit
图像调整函数。 我尝试了所有的插值标志,但都无济于事。
编辑:一个简单的代码来展示问题:
import numpy as np
from skimage.transform import resize
vals = [0, 1, 4, 6]
N, M = 100, 100
image = np.random.choice(vals, N * M).reshape(N, M).astype('uint8')
resized_image = resize(image, (50, 50), preserve_range=True).astype('uint8')
print('vals before resizing ', np.unique(image))
print('vals after resizing ', np.unique(resized_image))