import_images¶
-
menpo.io.import_images(pattern, 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
Imageor 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 returnedLazyListin a Python list.- 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_pathsfor more details of what images will be found.max_images (positive int, optional) – If not
None, only import the firstmax_imagesfound. Else, import all.shuffle (bool, optional) – If
True, the order of the returned images will be randomised. IfFalse, 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. IfNone, 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 assumesImageinstances 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
Trueprogress of the importing will be dynamically reported with a progress bar.
- Returns
lazy_list (
LazyListor generator ofImage) – ALazyListor generator yieldingImageinstances found to match the glob pattern provided.- Raises
ValueError – If no images are found at the provided glob.
Examples
Import images at 20% scale from a huge collection:
>>> rescale_20p = lambda x: x.rescale(0.2) >>> images = menpo.io.import_images('./massive_image_db/*') # Returns immediately >>> images = images.map(rescale_20p) # Returns immediately >>> images[0] # Get the first image, resize, lazily loaded