如何将代表40波段图像的数组保存到.tif文件 [英] how to save an array representing an image with 40 band to a .tif file

查看:177
本文介绍了如何将代表40波段图像的数组保存到.tif文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个尺寸为600×600×40的数组,每个波段(从40个波段开始)代表600×600的图像 我想将其保存到多波段.tif图像. 我已经从scikit-image和openCV中尝试了此功能,但是它们不能保存超过3个波段(作为RGB).

I have an array with 600×600×40 dimension that each band(from 40 band) represent a 600×600 image I want to save it to a multiple band .tif image. I have tried this functions from scikit-image and openCV but they can not save more than 3 band(as RGB).

import cv2
cv2.imwrite('image.tif',600by600_just3band_array)

推荐答案

tifffile( https://pypi .org/project/tifffile/)支持多渠道.tiff,并且具有类似于scikit-imageOpenCV的API:

tifffile (https://pypi.org/project/tifffile/) supports multi-channel .tiff's and has an API similar to the one of scikit-image or OpenCV:

In [1]: import numpy as np

In [2]: import tifffile

In [3]: # Channel dimension should come first

In [4]: x = np.random.randint(0, 255, 4*100*100).reshape((4, 100, 100))

In [5]: tifffile.imsave('test.tiff', x)

In [6]: y = tifffile.imread('test.tiff')

In [7]: np.all(np.equal(x, y))
Out[7]: True

这篇关于如何将代表40波段图像的数组保存到.tif文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆