繁体   English   中英

将[0,1]中的浮点像素数组转换为python中的灰度图像

[英]Converting an array of floating point pixels in [0,1] to grayscale image in python

我有一个[400,1]浮点数numpy数组,其间隔[0,1]表示图像的像素,即,如果将尺寸调整为20x20,则将是所需的图片。 我想将其转换为Python中的灰度图像。 为了完全重现我的错误,我将数组放在了pastebin链接中 我的代码是

pixels = np.array(pixels)
img = Image.fromarray(pixels.reshape((20,20)), mode='LA')
img = img.resize((140, 140), Image.LANCZOS)
img.show()

导致

在此处输入图片说明

该图像应该是7。

假设“ pixels”是介于0和1之间的浮点数的python列表

pixels = 255 * (1.0 - pixels)
pixels.resize((20,20))
im = Image.fromarray(pixels.astype(np.uint8), mode='L')
im = im.resize((140, 140))
im.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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