我有一个 4 波段多 channel 图像 (TIF),它是一个无符号的 16 位图像。我正在使用以下内容:
opencv2
python
我在代码的开头做了以下内容
import cv2
当我使用
i = cv2.imread('img.tif')
它正在读取所有四个波段,但作为 UINT8。当我使用
i = cv2.imread('img.tif', cv2.CV_16U)
它只读取图像的一个 channel 。 16bit unsigned 读取所有四个 channel 应该怎么做?
最佳答案
尝试传递标志 cv2.IMREAD_ANYDEPTH
。 documentation声明此标志将:
If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
i = cv2.imread('img.tif', flags=cv2.IMREAD_ANYDEPTH)
如果这不起作用,请尝试使用 cv2.IMREAD_UNCHANGED
标志。它没有记录,但看起来它也可以工作。
关于python - 在 Python OpenCV2 中打开多 channel 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17534489/