Reading and saving of images and videos.
Concatenate all images in the image collection into an array. | |
Load an image from file. | |
Load a collection of images. | |
Save an image to file. | |
Read SIFT or SURF features from externally generated file. | |
Read SIFT or SURF features from externally generated file. | |
Pop an image from the shared image stack. | |
Push an image onto the shared image stack. | |
Load and manage a collection of image files. | |
A class containing all frames from multi-frame TIFF images. |
skimage.io.concatenate_images(ic) [source]
Concatenate all images in the image collection into an array.
ican iterable of images The images to be concatenated.
array_catndarray An array having one more dimension than the images in ic.
If images in ic don’t have identical shapes.
concatenate_images receives any iterable object containing images, including ImageCollection and MultiImage, and returns a NumPy array.
skimage.io.imread(fname, as_gray=False, plugin=<DEPRECATED>, **plugin_args) [source]
Load an image from file.
fnamestr or pathlib.Path Image file name, e.g. test.jpg or URL.
as_graybool, optional If True, convert color images to gray-scale (64-bit floats). Images that are already in gray-scale format are not converted.
img_arrayndarray The different color bands/channels are stored in the third dimension, such that a gray-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.
plugin_argsDEPRECATED The plugin infrastructure is deprecated.
pluginDEPRECATED plugin is deprecated.
Deprecated since version 0.25.
skimage.io.imread_collection(load_pattern, conserve_memory=True, plugin=<DEPRECATED>, **plugin_args) [source]
Load a collection of images.
load_patternstr or list List of objects to load. These are usually filenames, but may vary depending on the currently active plugin. See ImageCollection for the default behaviour of this parameter.
conserve_memorybool, optional If True, never keep more than one in memory at a specific time. Otherwise, images will be cached once they are loaded.
icImageCollection Collection of images.
plugin_argsDEPRECATED The plugin infrastructure is deprecated.
pluginDEPRECATED plugin is deprecated.
Deprecated since version 0.25.
skimage.io.imread_collection_wrapper(imread) [source]
skimage.io.imsave(fname, arr, plugin=<DEPRECATED>, *, check_contrast=True, **plugin_args) [source]
Save an image to file.
fnamestr or pathlib.Path Target filename.
arrndarray of shape (M,N) or (M,N,3) or (M,N,4) Image data.
check_contrastbool, optional Check for low contrast and print warning (default: True).
plugin_argsDEPRECATED The plugin infrastructure is deprecated.
pluginDEPRECATED plugin is deprecated.
Deprecated since version 0.25.
skimage.io.load_sift(f) [source]
Read SIFT or SURF features from externally generated file.
This routine reads SIFT or SURF files generated by binary utilities from http://people.cs.ubc.ca/~lowe/keypoints/ and http://www.vision.ee.ethz.ch/~surf/.
This routine does not generate SIFT/SURF features from an image. These algorithms are patent encumbered. Please use skimage.feature.CENSURE instead.
filelikestring or open file Input file generated by the feature detectors from http://people.cs.ubc.ca/~lowe/keypoints/ or http://www.vision.ee.ethz.ch/~surf/ .
mode{‘SIFT’, ‘SURF’}, optional Kind of descriptor used to generate filelike.
datarecord array with fields row position of feature
column position of feature
feature scale
feature orientation
feature values
skimage.io.load_surf(f) [source]
Read SIFT or SURF features from externally generated file.
This routine reads SIFT or SURF files generated by binary utilities from http://people.cs.ubc.ca/~lowe/keypoints/ and http://www.vision.ee.ethz.ch/~surf/.
This routine does not generate SIFT/SURF features from an image. These algorithms are patent encumbered. Please use skimage.feature.CENSURE instead.
filelikestring or open file Input file generated by the feature detectors from http://people.cs.ubc.ca/~lowe/keypoints/ or http://www.vision.ee.ethz.ch/~surf/ .
mode{‘SIFT’, ‘SURF’}, optional Kind of descriptor used to generate filelike.
datarecord array with fields row position of feature
column position of feature
feature scale
feature orientation
feature values
skimage.io.pop() [source]
Pop an image from the shared image stack.
imgndarray Image popped from the stack.
skimage.io.push(img) [source]
Push an image onto the shared image stack.
imgndarray Image to push.
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.
load_patternstr or list of str Pattern string or list of strings to load. The filename path can be absolute or relative.
conserve_memorybool, optional If True, skimage.io.ImageCollection does not keep more than one in memory at a specific time. Otherwise, images will be cached once they are loaded.
fileslist of str If a pattern string is given for load_pattern, this attribute stores the expanded file list. Otherwise, this is equal to load_pattern.
load_funccallable imread by default. See Notes below.
**load_func_kwargsdict Any other keyword arguments are passed to load_func.
Note that files are always returned in alphanumerical order. Also note that slicing returns a new skimage.io.ImageCollection, not a view into the data.
ImageCollection image loading can be customized through load_func. For an ImageCollection ic, ic[5] calls load_func(load_pattern[5]) to load that image.
For example, here is an ImageCollection that, for each video provided, loads every second frame:
import imageio.v3 as iio3
import itertools
def vidread_step(f, step):
vid = iio3.imiter(f)
return list(itertools.islice(vid, None, None, step)
video_file = 'no_time_for_that_tiny.gif'
ic = ImageCollection(video_file, load_func=vidread_step, step=2)
ic # is an ImageCollection object of length 1 because 1 video is provided
x = ic[0]
x[5] # the 10th frame of the first video
Alternatively, if load_func is provided and load_pattern is a sequence, an skimage.io.ImageCollection of corresponding length will be created, and the individual images will be loaded by calling load_func with the matching element of the load_pattern as its first argument. In this case, the elements of the sequence do not need to be names of existing files (or strings at all). For example, to create an skimage.io.ImageCollection containing 500 images from a video:
class FrameReader:
def __init__ (self, f):
self.f = f
def __call__ (self, index):
return iio3.imread(self.f, index=index)
ic = ImageCollection(range(500), load_func=FrameReader('movie.mp4'))
ic # is an ImageCollection object of length 500
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)
>>> import imageio.v3 as iio3 >>> import skimage.io as io
# Where your images are located >>> data_dir = os.path.join(os.path.dirname(__file__), ‘../data’)
>>> coll = io.ImageCollection(data_dir + '/chess*.png') >>> len(coll) 2 >>> coll[0].shape (200, 200)
>>> image_col = io.ImageCollection([f'{data_dir}/*.png', '{data_dir}/*.jpg'])
>>> class MultiReader: ... def __init__ (self, f): ... self.f = f ... def __call__ (self, index): ... return iio3.imread(self.f, index=index) ... >>> filename = data_dir + '/no_time_for_that_tiny.gif' >>> ic = io.ImageCollection(range(24), load_func=MultiReader(filename)) >>> len(image_col) 23 >>> isinstance(ic[0], np.ndarray) True
__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.
arnp.ndarray An array having one more dimension than the images in self.
If images in the skimage.io.ImageCollection do not have identical shapes.
See also
property conserve_memory property files reload(n=None) [source]
Clear the image cache.
nNone or int Clear the cache for this image only. By default, the entire cache is erased.
class skimage.io.MultiImage(filename, conserve_memory=True, dtype=None, **imread_kwargs) [source]
Bases: ImageCollection
A class containing all frames from multi-frame TIFF images.
load_patternstr or list of str Pattern glob or filenames to load. The path can be absolute or relative.
conserve_memorybool, optional Whether to conserve memory by only caching the frames of a single image. Default is True.
MultiImage returns a list of image-data arrays. In this regard, it is very similar to ImageCollection, but the two differ in their treatment of multi-frame images.
For a TIFF image containing N frames of size WxH, MultiImage stores all frames of that image as a single element of shape (N, W, H) in the list. ImageCollection instead creates N elements of shape (W, H).
For an animated GIF image, MultiImage reads only the first frame, while ImageCollection reads all frames by default.
# Where your images are located >>> data_dir = os.path.join(os.path.dirname(__file__), ‘../data’)
>>> multipage_tiff = data_dir + '/multipage.tif' >>> multi_img = MultiImage(multipage_tiff) >>> len(multi_img) # multi_img contains one element 1 >>> multi_img[0].shape # this element is a two-frame image of shape: (2, 15, 10)
>>> image_col = ImageCollection(multipage_tiff) >>> len(image_col) # image_col contains two elements 2 >>> for frame in image_col: ... print(frame.shape) # each element is a frame of shape (15, 10) ... (15, 10) (15, 10)
__init__(filename, conserve_memory=True, dtype=None, **imread_kwargs) [source]
Load a multi-img.
concatenate() [source]
Concatenate all images in the collection into an array.
arnp.ndarray An array having one more dimension than the images in self.
If images in the skimage.io.ImageCollection do not have identical shapes.
See also
property conserve_memory property filename property files reload(n=None) [source]
Clear the image cache.
nNone or int Clear the cache for this image only. By default, the entire cache is erased.
© 2019 the scikit-image team
Licensed under the BSD 3-clause License.
https://scikit-image.org/docs/0.25.x/api/skimage.io.html