Corrected loadImageSeries type hint by radarhere · Pull Request #8624 · python-pillow/Pillow

Conversation

@radarhere

This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.

Two changes to loadImageSeries.

def loadImageSeries(filelist: list[str] | None = None) -> list[SpiderImageFile] | None:
"""create a list of :py:class:`~PIL.Image.Image` objects for use in a montage"""
if filelist is None or len(filelist) < 1:
return None
imglist = []
for img in filelist:
if not os.path.exists(img):
print(f"unable to find {img}")
continue
try:
with Image.open(img) as im:
im = im.convert2byte()
except Exception:
if not isSpiderImage(img):
print(f"{img} is not a Spider image file")
continue
im.info["filename"] = img
imglist.append(im)
return imglist
  1. convert2byte() is a SpiderImageFile method, so the image must be a SPIDER image to call that
  2. convert2byte() returns an Image instance, meaning that loadImageSeries returns a list of Images, not SpiderImageFiles.
def convert2byte(self, depth: int = 255) -> Image.Image:

Labels

2 participants

@radarhere @hugovk