[英]OpenCV - Reading a 16 bit grayscale image
I'm trying to read a 16 bit grayscale image using OpenCV 2.4 in Python, but it seems to be loading it as 8 bit.我正在尝试使用 Python 中的 OpenCV 2.4 读取 16 位灰度图像,但它似乎将其加载为 8 位。
I'm doing:我正在做:
im = cv2.imread(path,0)
print im
[[25 25 28 ..., 0 0 0]
[ 0 0 0 ..., 0 0 0]
[ 0 0 0 ..., 0 0 0]
...,
How do I get it as 16 bit?我如何将其设置为 16 位?
Figured it out.弄清楚了。 In case anyone else runs into this problem:
万一其他人遇到这个问题:
im = cv2.imread(path,-1)
Setting the flag to 0, to load as grayscale seems to default to 8 bit.将标志设置为 0,以灰度加载似乎默认为 8 位。 Setting to -1 loads the image as is.
设置为 -1 按原样加载图像。
为了提高可读性,使用标志cv2.IMREAD_ANYDEPTH
image = cv2.imread( path, cv2.IMREAD_ANYDEPTH )
I had the same issue (16-bit .tif loading as 8-bit using cv2.imread).我遇到了同样的问题(使用 cv2.imread 将 16 位 .tif 加载为 8 位)。 However, using the -1 flag didn't help.
但是,使用 -1 标志没有帮助。 Instead, I was able to load 16-bit images using the tifffile package.
相反,我能够使用 tifffile 包加载 16 位图像。
This question suggests that image = cv2.imread('16bit.png', cv2.IMREAD_UNCHANGED)
will also solve your problem. 这个问题表明
image = cv2.imread('16bit.png', cv2.IMREAD_UNCHANGED)
也可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.