Opening and visualizing images#

Most images with standard extensions (tif, png etc.) can be read using the skimage.io.imread function.

See also

To use imread you have three possibilities:

  • use the absolute path to an image file e.g. imread('/Users/username/Desktop/blobs.tif')

  • use a relative path to where you currently are, e.g. imread('data/blobs.tif') or imread('../../data/blobs.tif')

  • use a url that points to an image file, e.g. from a GitHub repository imread('https://github.com/haesleinhuepf/BioImageAnalysisNotebooks/raw/main/data/blobs.tif')

Here we use a relative path. Respective to the current notebook, the data in a sub-folder called data:

from skimage.io import imread

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

Displaying images#

There are many ways to display simple 2D images. In many notebooks and examples online, you will find examples using Matplotlib’s imshow function:

from matplotlib import pyplot as plt

plt.imshow(image);
../_images/6291f7d1f805102456af90eb5b07ef614488445fe5404599633d60678422fa6b.png

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

We can also change the color map, a.k.a. “lookup table” for the visualization.

plt.imshow(image, cmap="Greys_r")
<matplotlib.image.AxesImage at 0x7f447c0c26d0>
../_images/d0ed26ec95f6d3cd7cee1a0ba9354770b92e20cf1f9e911046fb37651c5ce088.png
plt.imshow(image, cmap="seismic")
<matplotlib.image.AxesImage at 0x7f447a719160>
../_images/e8c8acd1211aff4ae328732856498390edadcd475360e1fec1238892e6f203d4.png

Exercise#

Open the banana020.tif data set and visualize it in a yellowish colormap.