import_images, max_images=None, shuffle=False, landmark_resolver=<function same_name>, normalize=None, normalise=None, as_generator=False, verbose=False)[source]

Multiple image (and associated landmarks) importer.

For each image found creates an importer than returns a Image or subclass representing it. By default, landmark files sharing the same filename stem will be imported and attached with a group name based on the extension of the landmark file, although this behavior can be customised (see landmark_resolver). If the image defines a mask, this mask will be imported.

Note that this is a function returns a LazyList. Therefore, the function will return immediately and indexing into the returned list will load an image at run time. If all images should be loaded, then simply wrap the returned LazyList in a Python list.

  • pattern (str) – A glob path pattern to search for images. Every image found to match the glob will be imported one by one. See image_paths for more details of what images will be found.

  • max_images (positive int, optional) – If not None, only import the first max_images found. Else, import all.

  • shuffle (bool, optional) – If True, the order of the returned images will be randomised. If False, the order of the returned images will be alphanumerically ordered.

  • landmark_resolver (function or None, optional) – This function will be used to find landmarks for the image. The function should take one argument (the image itself) and return a dictionary of the form {'group_name': 'landmark_filepath'} Default finds landmarks with the same name as the image file. If None, landmark importing will be skipped.

  • normalize (bool, optional) – If True, normalize the image pixels between 0 and 1 and convert to floating point. If false, the native datatype of the image will be maintained (commonly uint8). Note that in general Menpo assumes Image instances contain floating point data - if you disable this flag you will have to manually convert the images you import to floating point before doing most Menpo operations. This however can be useful to save on memory usage if you only wish to view or crop images.

  • normalise (bool, optional) – Deprecated version of normalize. Please use the normalize arg.

  • as_generator (bool, optional) – If True, the function returns a generator and assets will be yielded one after another when the generator is iterated over.

  • verbose (bool, optional) – If True progress of the importing will be dynamically reported with a progress bar.


lazy_list (LazyList or generator of Image) – A LazyList or generator yielding Image instances found to match the glob pattern provided.


ValueError – If no images are found at the provided glob.


Import images at 20% scale from a huge collection:

>>> rescale_20p = lambda x: x.rescale(0.2)
>>> images ='./massive_image_db/*')  # Returns immediately
>>> images =  # Returns immediately
>>> images[0]  # Get the first image, resize, lazily loaded