python - 如何使用opencv从tif文件导入多个图层

标签 python image opencv computer-vision tiff

我正在使用 python (cv2) 导入具有三层的 .tif 文件,但我似乎只能导入一层。如何单独导入所有三层?

import cv2

img = cv2.imread('LanB2_KD1P2_31603_gut_2.tif', cv2.IMREAD_COLOR)

#extract blue channel
blue_channel = img[:,:,0]

#write blue channel to greyscale image
cv2.imwrite('blue_channel.jpg',blue_channel)

这从第一层中提取蓝色 channel ,但不知道如何获取其他层

最佳答案

更简单,你可以使用cv2.imreadmulti:

ret, image = cv2.imreadmulti('LanB2_KD1P2_31603_gut_2.tif', [], cv2.IMREAD_ANYCOLOR)

然后您可以通过索引访问每个层(例如 image[0])。

关于python - 如何使用opencv从tif文件导入多个图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63092811/

相关文章:

c++ - 将扭曲/转换后的图像与基本图像匹配的最快、最准确的方法?

python - 类型 'tensorflow.python.framework.ops.EagerTensor' 没有 len()

python - 在 dask 中为一个工作人员并行/分配子进程调用?

python - 在 pyspark 数据框中显示不同的列值

image - nodejs - 如何将文件中的图像数据添加到 Canvas 中

javascript - Firefox getElementById 的问题

latex - 在 LaTeX 中自动将图片调整为 A4

python - 如何使用 opencv python 填充多边形

python - 云中的 OpenCV

Python - export_graphviz class_name 类型错误