如何解决从多个TIFF格式图像中提取帧
我有一个需要分解的tiff图像数据集。每个文件有50帧,目前我正在一张一张地分解,但是与我拥有的图像数量相比,分解它们中的每一个都要花费很长时间。我的目标是针对文件夹中的每个tiff文件,我想将其分解并存储在单独的文件夹中,其中每个tiff图像将始终具有50帧,例如:
在C:\ Dataset \ tiff-images \
内部
我有tiff-image1,tiff-image2,tiffimage3,tiffimage4。
仍然在同一目录中,有以下文件夹:tiff-image1,tiff-image2,tiff-image3,tiff-image4。
基本上,我想简单地遍历目录中的多个tiff图像,并通过在没有文件夹的情况下创建一个文件夹来分解它们在各自的文件夹中。
我现在尝试的方法并不是完全理想的,并且需要很长时间才能完成此过程:
An error occurred while retrieving token from XML response: AADSTS90023: Invalid STS request.
Traceback (most recent call last):
File "/home/tacohen/ws-test/test/software-repo/devops/icetest/Office365-script.py",line 28,in <module>
if ctx_auth.acquire_token_for_user(username,password):
File "/usr/local/lib/python3.6/dist-packages/office365/runtime/auth/authentication_context.py",line 47,in acquire_token_for_user
if not self.provider.acquire_token():
File "/usr/local/lib/python3.6/dist-packages/office365/runtime/auth/providers/saml_token_provider.py",line 68,in acquire_token
return self._acquire_authentication_cookie(token,user_realm.IsFederated)
File "/usr/local/lib/python3.6/dist-packages/office365/runtime/auth/providers/saml_token_provider.py",line 232,in _acquire_authentication_cookie
self._auth_cookies[name] = cookies[name]
KeyError: 'FedAuth'
解决方法
您可以使用os
模块进行此类自动化。
检查一下:
import os
from PIL import Image
# enter the main folder path here
path = './'
lsdir = os.listdir(path)
for f in lsdir:
if os.path.isfile(f):
file,ext = os.path.splitext(f)
if ext in ['.tif','.tiff']:
fldr = os.path.join(path,file)
if not os.path.isdir(fldr):
os.mkdir(fldr)
imgpath = os.path.join(path,f)
img = Image.open(imgpath)
for i in range(50):
try:
img.seek(i)
img.save(f'{fldr}/decomp{i}.tif')
except EOFError:
break
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。