Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 647
user10482281 Avatar asked Dec 06 '22 10:12

user10482281


1 Answers

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
like image 147
soupault Avatar answered Jan 08 '23 01:01

soupault