gpt4 book ai didi

python - 如何调整图像大小但保持 sk-image 中的像素值?

转载 作者:行者123 更新时间:2023-12-04 01:34:55 24 4
gpt4 key购买 nike

我想调整图像大小。我的图像包含特定值 [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))

最佳答案

套装anti_aliasingFalse :

resized_image = resize(image, (50, 50), order=0, preserve_range=True, anti_aliasing=False).astype('uint8')

anti_aliasingbool, optional
Whether to apply a Gaussian filter to smooth the image prior to down-scaling. It is crucial to filter when down-sampling the image to avoid aliasing artifacts.



混叠滤波器应用高斯滤波器,产生新值。

结果:
vals before resizing  [0 1 4 6]
vals after resizing [0 1 4 6]

关于python - 如何调整图像大小但保持 sk-image 中的像素值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59907635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com