3. Getting started#

scikit-image is an image processing Python package that works with numpy arrays. The package is imported as skimage:

>>> import skimage as ski

Most functions of skimage are found within submodules:

>>> camera = ski.data.camera()

A list of submodules and functions is found on the API reference webpage.

Within scikit-image, images are represented as NumPy arrays, for example 2-D arrays for grayscale 2-D images

>>> type(camera)
<type 'numpy.ndarray'>
>>> # An image with 512 rows and 512 columns
>>> camera.shape
(512, 512)

The skimage.data submodule provides a set of functions returning example images, that can be used to get started quickly on using scikit-image’s functions:

>>> coins = ski.data.coins()
>>> threshold_value = ski.filters.threshold_otsu(coins)
>>> threshold_value
107

Of course, it is also possible to load your own images as NumPy arrays from image files, using skimage.io.imread():

>>> import os
>>> filename = os.path.join(skimage.data_dir, 'moon.png')
>>> moon = ski.io.imread(filename)

Use natsort to load multiple images

>>> import os
>>> from natsort import natsorted, ns
>>> list_files = os.listdir('.')
>>> list_files
['01.png', '010.png', '0101.png', '0190.png', '02.png']
>>> list_files = natsorted(list_files)
>>> list_files
['01.png', '02.png', '010.png', '0101.png', '0190.png']
>>> image_list = []
>>> for filename in list_files:
...   image_list.append(ski.io.imread(filename))