import_images

menpo.io.base.import_images(pattern, max_images=None, landmark_resolver=None, verbose=False)[source]

Multiple image import generator.

Makes it’s best effort to import and attach relevant related information such as landmarks. It searches the directory for files that begin with the same filename and end in a supported extension.

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

The glob path pattern to search for images.

max_images : positive int, optional

If not None, only import the first max_images found. Else, import all.

landmark_resolver : function, optional

If not None, this function will be used to find landmarks for each image. The function should take one argument (an image itself) and return a dictionary of the form {'group_name': 'landmark_filepath'}

verbose : bool, optional

If True progress of the importing will be dynamically reported.

Raises:

ValueError :

If no images are found at the provided glob.

Examples

Import crops of the top 100 square pixels from a huge collection of images

>>> images = []
>>> for im in import_images('./massive_image_db/*'):
>>>    im.crop_inplace((0, 0), (100, 100))  # crop to a sensible size as we go
>>>    images.append(im)