简体   繁体   English

你如何在python中读取32位TIFF图像?

[英]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.

相关问题 读取 Tensorflow 中的 32 位 TIFF 图像 - Reading a 32-bit TIFF image in Tensorflow 在Python中,如何确定内核是以32位还是64位模式运行? - In Python, how do you determine whether the kernel is running in 32-bit or 64-bit mode? 将 32 位 TIFF 转换为 8 位 TIFF,同时在 python 中保留元数据和标签? - Converting 32-bit TIFF to 8-bit TIFF while retaining metadata and tags in python? 如何在Snow Leopard和其他32位/ 64位问题上强制Python为32位 - How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions 如何在Python中读取具有32位浮点数,64位浮点数和另一个32位浮点数的二进制文件 - How to read a binary file with a 32-bit float, a 64-bit float and another-32 bit float in Python Python-如何使用Open-CV或PIL将24位PNG图像转换为32位 - Python - how to convert a 24-bit PNG image to 32-bit using Open-cv or PIL 如何在64位CentOS 6上编译和运行32位Python? - How do I compile and run 32-bit Python on 64-bit CentOS 6? 您可以在Mac版Enthought Canopy上运行32位python吗? - Can you run 32-bit python on Enthought Canopy for Mac? 如何使用 python 读取单通道 32 位整数图像? - How can I read single-channel 32-bit integer images with python? Python 截断为 32 位 - Python Truncating to 32-bit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM