在PIL中处理分块金字塔tiff图像 - Python 2.7
我有一些tiff格式的图片,这些图片有7到8个不同的层级。这些图片是用vips这个工具生成的。我尝试过在这个StackOverflow问题中提到的方法。我也试过这个:
im = Image.open("E:\\tiled_pyr.tif")
for i in range(7):
try:
im.seek(i)
print im.size[0]
print im.size[1]
except EOFError:
# Not enough frames in im
break
但是,当我开始逐层处理时,出现了这个错误:
IOError: decoder tiff_adobe_deflate not available
我想做的是在最高分辨率或最高层级上裁剪这个ptif,然后对裁剪后的部分进行一些分析。
请问用PIL可以做到吗?我需要其他工具吗?谢谢!
1 个回答
1
libvips的Python绑定库pyvips现在可以在Windows上使用了,所以你可以这样做:
import pyvips
# this will open the highest resolution layer
image = pyvips.Image.new_from_file("somefile.tif")
# crop out an area
area = image.crop(x, y, w, h)
# ... do what you like
print('average pixel value of crop is', area.avg())
详情请查看