带有多个图像的 PIL Tiff 文件,用于在 python 中分离图像

问题描述

我需要为目录中的所有 tiff 文件运行一个循环,以获取包含在每个 tiff 文件中的单独 tiff 图像及其各自的名称页面

例如:- example1.tif 包含 80 页,所以我想要图片作为 example_page1 等等..

使用 PIL ImageSequence,它会为多个 tiff 文件引发错误并在 OSError -2 处退出

文件夹结构-
-Dir1
-Example1.tiff
-Example2.tiff
-Example3.tiff

需要结果
-Dir1
-Example1_page1.tiff
-Example1_page2.tiff
-Example1_page3.tiff
.
.
-Example1_page80.tiff
.
.
.
.
-Example3_page80.tiff

我使用的代码:-

def tiff_sep(file):
    new_file = Image.open(file) 
    for i,page in enumerate(ImageSequence.Iterator(file)): 
        print(i,page)
        page.save(r"C:\Users\Downloads\ims\20210527114557_%d.tiff" % i)


if __name__=="__main__":
    for file in os.listdir('.'):
        if file.endswith('.tiff') or file.endswith('.tif'):
            print(file)
            tiff_sep(file)

        

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)