© 2021 Tom Röschinger. This work is licensed under a Creative Commons Attribution License CC-BY 4.0. All code contained herein is licensed under an MIT license
This notebook is heavily inspired by this lesson by Justin Bois.
import os
# For numerical computation
import numpy as np
import pandas as pd
# For plotting
import matplotlib.pyplot as plt
import seaborn as sns
import colorcet as cc
# For image analysis
import skimage.io
import skimage.filters
import skimage.morphology
import scipy.ndimage
import skimage.segmentation
# This enables high resolution graphics inline
%config InlineBackend.figure_format = 'retina'
pn.extension()
sns.set()
In this notebook we will take a look at images obtained with electron microscopy of SARS-Cov2 virions outside a cell. This images were sent to us by Elizabeth Fischer. We will try to identify the virion particles in the image and then obtain their diameter.
Image analysis is far from trivial, and often there are many different ways one can take to come to a conclusion, and rarely there is one optimal way. So here we explore two different ways of identifying virions, but there are many more ways to get equivalent or even better results.
Here we define the path to the location where the images are stored. Change this accordingly. We use skimage
to read the image.
# Define directory where images exist
filepath = "../../data/VeroCells-24hSARS-CoV2_i013.tif"
# Read example image into memory
im = skimage.io.imread(filepath)
# Let's show an image
im
array([[180, 148, 147, ..., 102, 104, 96], [158, 168, 161, ..., 91, 98, 95], [164, 151, 131, ..., 91, 95, 92], ..., [ 83, 87, 87, ..., 213, 217, 229], [ 81, 87, 95, ..., 223, 211, 228], [ 89, 88, 82, ..., 216, 220, 206]], dtype=uint8)
Here we can see that this image is simply a two dimensional array of integers. From this matrix of integers we are going to identify virions and determine their size.
We write a short function to plot images, since we will be doing this task quite a lot.
def plot_image(im, cmap=plt.cm.Greys_r, scale=1):
"Returns a image representation of a 2D array"
fig, ax = plt.subplots(figsize=(8 * scale, 8 * scale))
ax.imshow(im, cmap=cmap, aspect=1)
ax.grid(False)
return ax
plot_image(im);