[英]Convert image file to float array in Python
How can I convert an image to an array of float numbers? 如何将图像转换为浮点数数组? img = cv2.imread('img.png')
img = cv2.imread('img.png')
and now convert img to float so I get for print(img[0,0]) something like "[ 4.0 2.0 0.0] instead of [4 2 0] 现在将img转换为float,这样我得到print(img [0,0])就像“ [4.0 2.0 0.0]而不是[4 2 0]
Do you have an idea? 你有想法吗? Thank you very much!
非常感谢你!
You can convert the list of the integers to list of floats as [float(i) for i in values]
with list comprehension. 您可以使用列表推导将整数列表转换为
[float(i) for i in values]
列表。
An other option is to convert the img
variable as numpy.ndarray
to an other numpy.ndarray
which contains float
values: 另一种选择是将
img
变量作为numpy.ndarray
转换为另一个包含float
值的numpy.ndarray
:
img = img.astype(float)
After this assignment the results will contain float values. 分配后,结果将包含浮点值。
You can also use Skimage's img_to_float() function. 您也可以使用Skimage的img_to_float()函数。
image = io.imread('imagefilepath')
image = skimage.img_as_float(image)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.