Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中读取带符号的16位TIFF?_Python_Opencv_Tiff_Signed - Fatal编程技术网

如何在python中读取带符号的16位TIFF?

如何在python中读取带符号的16位TIFF?,python,opencv,tiff,signed,Python,Opencv,Tiff,Signed,我使用OpenCV的imread()读取TIFF。但价值观和我已经知道的不一样。此TIFF是有符号16位,它有负值。使用imread()的值范围为0~65535,它是无符号16位 import cv2 as cv img = cv.imread("MYD_20140102.tif",2) print img print img.dtype print img.shape print img.min() print img.max() cv.namedWindow("Image") cv.i

我使用OpenCV的imread()读取TIFF。但价值观和我已经知道的不一样。此TIFF是有符号16位,它有负值。使用imread()的值范围为0~65535,它是无符号16位

import cv2 as cv

img = cv.imread("MYD_20140102.tif",2)
print img
print img.dtype 
print img.shape
print img.min()
print img.max()

cv.namedWindow("Image")
cv.imshow("Image",img)
cv.waitKey(0)
cv.destroyAllWindows()


output:
img=[[55537 55537 55537 ... 55537 55537 55537]
 [55537 55537 55537 ... 55537 55537 55537]
 [55537 55537 55537 ... 55537 55537 55537]
 ...
 [55537 55537 55537 ... 55537 55537 55537]
 [55537 55537 55537 ... 55537 55537 55537]
 [55537 55537 55537 ... 55537 55537 55537]]
type=uint16
shape=(2318, 2296)
imgMin=0
imgMAX=65535
库文件()正是您想要的。 以下是创建int16 numpy阵列,将其保存在磁盘上,然后重新加载的示例:

import tifffile
import numpy as np

# random array of numbers between -5 and 5
a = np.asarray(np.random.rand(8, 8)*10-5, dtype=np.int16)
# save array to disk and display its content
tifffile.imsave("test.tiff", a)
print(str(a) + "\n")
# load the array back from the disk and display its content too
b = tifffile.imread("test.tiff")
print(b)
输出:

a=[[ 1 -1 -3  2  3 -1  4  0]
   [ 2 -2  2  0 -1  0  3 -4]
   [ 0 -4  3  2 -4 -2  0 -3]
   [ 0 -1  0 -2  0  3 -3  1]
   [ 0 -4  3  1 -1  3  2  3]
   [-3  4  4  3 -3  1 -3 -2]
   [ 4  0 -4 -2  1 -3  3 -3]
   [ 4  0  4  2  3  1 -2 -4]]

b=[[ 1 -1 -3  2  3 -1  4  0]
   [ 2 -2  2  0 -1  0  3 -4]
   [ 0 -4  3  2 -4 -2  0 -3]
   [ 0 -1  0 -2  0  3 -3  1]
   [ 0 -4  3  1 -1  3  2  3]
   [-3  4  4  3 -3  1 -3 -2]
   [ 4  0 -4 -2  1 -3  3 -3]
   [ 4  0  4  2  3  1 -2 -4]]