Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
938 views
in Technique[技术] by (71.8m points)

opencv - how to save an array representing an image with 40 band to a .tif file

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...