小编Eun*_* TT的帖子

如何调整图像大小但使用python保留像素值

我正在处理一些图像,我想将它们的大小从 1080 * 1920 调整为 480 * 640。我将每个像素归类到一个特定的类中,因此每个像素都有一个唯一的值。但是,如果我调整图像大小,这些像素值会改变。

python
resized = cv2.resize(image, (640, 480), interpolation = cv2.INTER_AREA)
print(set(resized.flat)) --> a dict {0,1,2,3,4……,38,39,40}
print(set(image.flat)) --> a dict {0,10,40}

# image size is 1080 * 1920
# resized size is 480 * 640

desired_image = cv2.imread(desired_image_path,cv2.IMREAD_GRAYSCALE).astype(np.uint8)
print(set(desired_image.flat)) --> a dict {0,10,40}

# desired_image size is 480 * 640
Run Code Online (Sandbox Code Playgroud)

我希望获得所需的图像,其大小为 480 * 640,没有任何裁剪,并保持像素值相同。现在我有正确的尺寸,但像素值变化很大。

python opencv image python-imaging-library

3
推荐指数
1
解决办法
1962
查看次数

标签 统计

image ×1

opencv ×1

python ×1

python-imaging-library ×1