python - 在 Python OpenCV2 中打开多 channel 图像

标签 python image opencv

我有一个 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_ANYDEPTHdocumentation声明此标志将:

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/

相关文章:

python - 如何在 Python 上使用 Opencv 在内存中编码/解码 Webp 格式?

python - Pandas DataFrame - 根据其他列分配 1,0 值

python - 使用 Python 在 cmd 中打印颜色?

javascript - DOM react 时间过长

image-processing - CUDA 或 OpenCV 上的图像处理?

opencv - 使用C++和opencv的第一个项目,什么都找不到

python - 如何在 python 中将 truetypefont 文件转换为 svg

python - grep 与 python 子进程替换

css - 如何在不拉伸(stretch)和扭曲图像的情况下调整图像大小

javascript - 尝试使用 css 将图像添加到 SVG 圆