简体   繁体   English

我正在尝试读取图像并将其转换为 python 中的双精度图像,我正在使用 cv2 库

[英]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.

相关问题 我正在尝试使用 opencv python 库使用 cv2.imwrite() function 将图像保存到文件,但它显示错误 - I am trying to save an image to a file by using opencv python library using cv2.imwrite() function but it shows an error 读取双像 cv2 python - Read double image cv2 python 尝试在 python (Ubuntu 18.04) 中导入 cv2 时收到并导入错误 - I am receiving and import error when trying to import cv2 in python (Ubuntu 18.04) Python:为什么我无法使用 cv2 的功能? - Python: Why am I not able to use the functions of cv2? 在python中,使用cv2库; 如何将一张图像平铺成第二张图像? - In python, using the cv2 library; how can I tile one image into a second image? 为什么我在 python 中使用 detectMultiScale 时出现打开 cv2 错误 - Why am I getting open cv2 error when I use detectMultiScale in python 当我尝试使用 droidcam 运行我的 CV2 python 代码时出现错误 - When I try to run my CV2 python code with droidcam I am getting error 我正在尝试将图像上传到Firebase,但出现错误。 我正在使用python 3.6.1 - i am trying to upload an image to firebase but i am getting an error. i am using python 3.6.1 我无法从pycharm软件包安装程序安装cv2 - I am unable to install cv2 from pycharm package installer 为什么我在raspbianOS中而不是raspberrypi shell中出现cv2错误 - Why am I getting cv2 error in raspbianOS and not raspberrypi shell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM