imagecollection

ImageCollection

class skimage.io.ImageCollection(load_pattern, conserve_memory=True, load_func=None, **load_func_kwargs) [source]

Bases: object

Load and manage a collection of image files.

Note that files are always stored in alphabetical order. Also note that slicing returns a new ImageCollection, not a view into the data.

Parameters:

load_pattern : str or list

Pattern glob or filenames to load. The path can be absolute or relative. Multiple patterns should be separated by os.pathsep, e.g. ‘/tmp/work/.png:/tmp/other/.jpg’. Also see implementation notes below.

conserve_memory : bool, optional

If True, never keep more than one in memory at a specific time. Otherwise, images will be cached once they are loaded.

Other Parameters:

load_func : callable

imread by default. See notes below.

Notes

ImageCollection can be modified to load images from an arbitrary source by specifying a combination of load_pattern and load_func. For an ImageCollection ic, ic[5] uses load_func(file_pattern[5]) to load the image.

Imagine, for example, an ImageCollection that loads every tenth frame from a video file:

class AVILoader:
    video_file = 'myvideo.avi'

    def __call__(self, frame):
        return video_read(self.video_file, frame)

avi_load = AVILoader()

frames = range(0, 1000, 10) # 0, 10, 20, ...
ic = ImageCollection(frames, load_func=avi_load)

x = ic[5] # calls avi_load(frames[5]) or equivalently avi_load(50)

Another use of load_func would be to convert all images to uint8:

def imread_convert(f):
    return imread(f).astype(np.uint8)

ic = ImageCollection('/tmp/*.png', load_func=imread_convert)

For files with multiple images, the images will be flattened into a list and added to the list of available images. In this case, load_func should accept the keyword argument img_num.

Examples

>>> import skimage.io as io
>>> from skimage import data_dir
>>> coll = io.ImageCollection(data_dir + '/chess*.png')
>>> len(coll)
2
>>> coll[0].shape
(200, 200)
>>> ic = io.ImageCollection('/tmp/work/*.png:/tmp/other/*.jpg')

Attributes

files (list of str) If a glob string is given for load_pattern, this attribute stores the expanded file list. Otherwise, this is simply equal to load_pattern.
__init__(load_pattern, conserve_memory=True, load_func=None, **load_func_kwargs) [source]

Load and manage a collection of images.

concatenate() [source]

Concatenate all images in the collection into an array.

Returns:

ar : np.ndarray

An array having one more dimension than the images in self.

Raises:

ValueError

If images in the ImageCollection don’t have identical shapes.

conserve_memory
files
reload(n=None) [source]

Clear the image cache.

Parameters:

n : None or int

Clear the cache for this image only. By default, the entire cache is erased.

doc_scikit_image
2017-01-12 17:21:24
Comments
Leave a Comment

Please login to continue.