[英]How do you read a 32-bit TIFF image in python?
I want to read 32-bit float image files with python to do some image analysis.我想用python读取32位浮点图像文件来做一些图像分析。
I have tried我试过了
import matplotlib.pyplot as plt
im = plt.imread('path_to_file.tif')
But, this only reads the data as 8-bit integer values.但是,这只会将数据读取为 8 位整数值。 Is there a way to provide imread() with the right data type?
有没有办法为 imread() 提供正确的数据类型?
-- Well, it formerly worked out of the box with 16-bit TIFF files, but doesn't with 32-bit floats. -- 好吧,它以前可以使用 16 位 TIFF 文件开箱即用,但不适用于 32 位浮点数。
I experienced a similar problem trying to read single-channel 32-bit integer images.我在尝试读取单通道 32 位整数图像时遇到了类似的问题。 The solution I came up with was:
我想出的解决方案是:
from skimage import io
im = io.imread('path_to_file.tif')
If you have OpenCV installed on your computer you could also try:如果您的计算机上安装了 OpenCV,您还可以尝试:
import cv2
im = cv2.imread('path_to_file.tif', -1)
Hope this helps希望这有帮助
I found a way via PIL, which is:我通过 PIL 找到了一种方法,即:
from matplotlib import pyplot as plt
from matplotlib import cm
from PIL import Image
from numpy import array
im = Image.open('path_to_file.tif')
ncols, nrows = im.size
ima = array(im.getdata()).reshape((nrows, ncols))
plt.imshow(ima, cmap=cm.Greys_r)
May be that helps someone.可能对某人有帮助。
S秒
This worked for me (the key flag being IMREAD_ANYDEPTH
):这对我
IMREAD_ANYDEPTH
(关键标志是IMREAD_ANYDEPTH
):
cv2.imread(fullImagePath, flags=(cv2.IMREAD_GRAYSCALE | cv2.IMREAD_ANYDEPTH))
I found it here: https://github.com/opencv/opencv/issues/7025我在这里找到了: https : //github.com/opencv/opencv/issues/7025
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.