# import_images¶

menpo.io.import_images(pattern, max_images=None, shuffle=False, landmark_resolver=<function same_name>, normalise=True, verbose=False)[source]

Multiple image (and associated landmarks) importer.

For each image found yields an 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 generator function. This allows for pre-processing of data to take place as data is imported (e.g. cropping images to landmarks as they are imported for memory efficiency).

Parameters: 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, 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. normalise (bool, optional) – If True, normalise 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. verbose (bool, optional) – If True progress of the importing will be dynamically reported with a progress bar. generator (generator yielding Image or list of) – Generator yielding Image instances found to match the glob pattern provided. ValueError – If no images are found at the provided glob.

Examples

Import images at 20% scale from a huge collection:

>>> images = []
>>> for img in menpo.io.import_images('./massive_image_db/*'):
>>>    # rescale to a sensible size as we go
>>>    images.append(img.rescale(0.2))