Saw*_*aha 3 python image-processing python-imaging-library
我正在尝试用 python 读取这个tiff 图像。我已经尝试过 PIL 并保存此图像。该过程进行得很顺利,但输出图像似乎很暗。这是我使用的代码。
from PIL import Image
im = Image.open('file.tif')
imarray = np.array(im)
data = Image.fromarray(imarray)
data.save('x.tif')
Run Code Online (Sandbox Code Playgroud)
如果我做错了什么,或者是否有任何其他工作方式来读取和保存 tif 图像,请告诉我。我主要需要它作为 NumPy 数组来进行处理。
问题很简单,就是图像很暗。如果你用 PIL 打开它,并转换为 Numpy 数组,你可以看到最大亮度为 2455,在可能范围为 0..65535 的 16 位图像上,意味着它只有 2455/65535,即 3.7% 亮度。
from PIL import Image
# Open image
im = Image.open('5 atm_gain 80_C001H001S0001000025.tif')
# Make into Numpy array
na = np.array(im)
print(na.max()) # prints 2455
Run Code Online (Sandbox Code Playgroud)
因此,您需要标准化图像或放大亮度。一个非常粗略的方法是乘以 50,例如:
Image.fromarray(na*50).show()
Run Code Online (Sandbox Code Playgroud)
但实际上,您应该使用适当的标准化,例如PIL.ImageOps.autocontrast()或 OpenCV normalize()。
| 归档时间: |
|
| 查看次数: |
6665 次 |
| 最近记录: |