[英]I am trying to read an image and convert it to double in python , I am using cv2 library
I tried doing the same thing in Matlab by reading the image using imread and then converting it to type double using im2double, how can I achieve the same thing in python or cv2 library?.我尝试在 Matlab 中通过使用 imread 读取图像然后使用 im2double 将其转换为 double 类型来做同样的事情,我怎样才能在 python 或 cv2 库中实现同样的事情?
I tried using我尝试使用
img=imread('pathofmyimage')
double=np.asarray(img,dtype=np.float64)
but I am not sure of this method但我不确定这种方法
You could just say你可以说
float_img = img.astype(np.float64)
But your way works too.但你的方法也行得通。 The result from both methods will be equal.
两种方法的结果将相同。
To find out the type of an array, look at its .dtype
.要找出数组的类型,请查看其
.dtype
。 imread()
returns np.uint8
by default, with values ranging 0 to 255, but it can return arrays of other types, if given the right flag. imread()
默认返回np.uint8
,值范围为 0 到 255,但如果给出正确的标志,它可以返回其他类型的 arrays。 That is detailed in the docs.这在文档中有详细说明。
After conversion with astype
(or asarray
), the values will still be in the range of 0 to 255, just in a different data type.使用
astype
(或asarray
)转换后,值仍将在 0 到 255 的范围内,只是数据类型不同。 If you need them to be ranged 0.0 to 1.0, you'd need to scale the array (divide/multiply).如果您需要它们的范围为 0.0 到 1.0,则需要缩放数组(除法/乘法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.