Utilities to read and write images in various formats.
The following plug-ins are available:
Bases: numpy.ndarray
Class representing Image data.
These objects have tags for image metadata and IPython display protocol methods for image display.
Parameters: | arr : ndarray
kwargs : Image tags as keywords
|
---|
Attributes
tags | dict | Meta-data. |
x.__init__(...) initializes x; see help(type(x)) for signature
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
conserve_memory : bool, optional
|
---|---|
Other Parameters: | |
load_func : callable
|
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)
Examples
>>> import skimage.io as io
>>> from skimage import data_dir
>>> coll = io.ImageCollection(data_dir + '/lena*.png')
>>> len(coll)
2
>>> coll[0].shape
(512, 512, 3)
>>> ic = io.ImageCollection('/tmp/work/*.png:/tmp/other/*.jpg')
Attributes
files |
Load and manage a collection of images.
Concatenate all images in the collection into an array.
Returns: | ar : np.ndarray
|
---|---|
Raises: | ValueError :
|
See also
Clear the image cache.
Parameters: | n : None or int
|
---|
Bases: object
A class containing a single multi-frame image.
Parameters: | filename : str
conserve_memory : bool, optional
|
---|
Notes
If conserve_memory=True the memory footprint can be reduced, however the performance can be affected because frames have to be read from file more often.
The last accessed frame is cached, all other frames will have to be read from file.
The current implementation makes use of PIL.
Examples
>>> from skimage import data_dir
>>> img = MultiImage(data_dir + '/multipage.tif')
>>> len(img)
2
>>> for frame in img:
... print(frame.shape)
(15, 10)
(15, 10)
Load a multi-img.
Concatenate all images in the multi-image into an array.
Returns: | ar : np.ndarray
|
---|---|
Raises: | ValueError :
|
See also
skimage.io.call_plugin(kind, *args, **kwargs) | Find the appropriate plugin of ‘kind’ and execute it. |
skimage.io.concatenate_images(ic) | Concatenate all images in the image collection into an array. |
skimage.io.find_available_plugins([loaded]) | List available plugins. |
skimage.io.imread(fname[, as_grey, plugin, ...]) | Load an image from file. |
skimage.io.imread_collection(load_pattern[, ...]) | Load a collection of images. |
skimage.io.imread_collection_wrapper(imread) | |
skimage.io.imsave(fname, arr[, plugin]) | Save an image to file. |
skimage.io.imshow(arr[, plugin]) | Display an image. |
skimage.io.load_sift(f) | Read SIFT or SURF features from a file. |
skimage.io.load_surf(f) | Read SIFT or SURF features from a file. |
skimage.io.plugin_info(plugin) | Return plugin meta-data. |
skimage.io.plugin_order() | Return the currently preferred plugin order. |
skimage.io.pop() | Pop an image from the shared image stack. |
skimage.io.push(img) | Push an image onto the shared image stack. |
skimage.io.reset_plugins() | |
skimage.io.show() | Display pending images. |
skimage.io.use_plugin(name[, kind]) | Set the default plugin for a specified operation. |
Find the appropriate plugin of ‘kind’ and execute it.
Parameters: | kind : {‘imshow’, ‘imsave’, ‘imread’, ‘imread_collection’}
plugin : str, optional
*args, **kwargs : arguments and keyword arguments
|
---|
Concatenate all images in the image collection into an array.
Parameters: | ic: an iterable of images (including ImageCollection and MultiImage) :
|
---|---|
Returns: | ar : np.ndarray
|
Raises: | ValueError :
|
List available plugins.
Parameters: | loaded : bool
|
---|---|
Returns: | p : dict
|
Load an image from file.
Parameters: | fname : string
as_grey : bool
plugin : str
|
---|---|
Returns: | img_array : ndarray
|
Other Parameters: | |
plugin_args : keywords
|
Load a collection of images.
Parameters: | load_pattern : str or list
conserve_memory : bool, optional
|
---|---|
Returns: | ic : ImageCollection
|
Other Parameters: | |
plugin_args : keywords
|
Save an image to file.
Parameters: | fname : str
arr : ndarray of shape (M,N) or (M,N,3) or (M,N,4)
plugin : str
|
---|---|
Other Parameters: | |
plugin_args : keywords
|
Display an image.
Parameters: | arr : ndarray or str
plugin : str
|
---|---|
Other Parameters: | |
plugin_args : keywords
|
Read SIFT or SURF features from a file.
Parameters: | f : string or open file
|
---|---|
Returns: | data : record array with fields
|
Read SIFT or SURF features from a file.
Parameters: | f : string or open file
|
---|---|
Returns: | data : record array with fields
|
Return plugin meta-data.
Parameters: | plugin : str
|
---|---|
Returns: | m : dict
|
Return the currently preferred plugin order.
Returns: | p : dict
|
---|
Pop an image from the shared image stack.
Returns: | img : ndarray
|
---|
Push an image onto the shared image stack.
Parameters: | img : ndarray
|
---|
Display pending images.
Launch the event loop of the current gui plugin, and display all pending images, queued via imshow. This is required when using imshow from non-interactive scripts.
A call to show will block execution of code until all windows have been closed.
Examples
>>> import skimage.io as io
>>> for i in range(4):
... io.imshow(np.random.random((50, 50)))
>>> io.show()
Set the default plugin for a specified operation. The plugin will be loaded if it hasn’t been already.
Parameters: | name : str
kind : {‘imsave’, ‘imread’, ‘imshow’, ‘imread_collection’}, optional
|
---|
See also
Examples
To use Matplotlib as the default image reader, you would write:
>>> from skimage import io
>>> io.use_plugin('matplotlib', 'imread')
To see a list of available plugins run io.available_plugins. Note that this lists plugins that are defined, but the full list may not be usable if your system does not have the required libraries installed.