Working with images#

For analysing image data, we need to open them, apply filters to them, segment objects in the image and do measurements.

See also

Opening images#

Most images read using the imread function. In case your image doesn’t open, you should consult the documentation of the given file format. Also check next section.

from skimage.io import imread

image = imread('../../data/blobs.tif')

Images are just matrices of intensities. However, showing them as such is not convenient.

image
array([[ 40,  32,  24, ..., 216, 200, 200],
       [ 56,  40,  24, ..., 232, 216, 216],
       [ 64,  48,  24, ..., 240, 232, 232],
       ...,
       [ 72,  80,  80, ...,  48,  48,  48],
       [ 80,  80,  80, ...,  48,  48,  48],
       [ 96,  88,  80, ...,  48,  48,  48]], dtype=uint8)

Image visualization#

For visualizing images in notebooks, we can use the imshow function from the scikit-image library.

from skimage.io import imshow

imshow(image)
<matplotlib.image.AxesImage at 0x2d0adef0e50>
../_images/01_Working_with_images_5_1.png

Anothter example is the imshow function from the matplotlib library.

import matplotlib.pyplot as plt

plt.imshow(image)
<matplotlib.image.AxesImage at 0x2d0adf3e6a0>
../_images/01_Working_with_images_7_1.png

Lookup tables (a.k.a. color maps)#

We can also change the look-up table, a.k.a. “color map” for the visualization. Available options can be found in the documentation of each function.

imshow(image, cmap="hot")
<matplotlib.image.AxesImage at 0x2d0adfadf70>
../_images/01_Working_with_images_9_1.png
imshow(image, cmap="viridis")
<matplotlib.image.AxesImage at 0x2d0ae039190>
../_images/01_Working_with_images_10_1.png