Extracting cell geometry from Atomic Force Microscopy

Part 1: Static analysis

biology
bioinformatics
Authors
Affiliations

Clément Soubrier

KDD Group

Khanh Dao Duc

Published

July 31, 2024

We present here the protocole to process biological images such as bacteria atomic force miroscopy data. We want to study the bacteria cell shape and extract the main geometrical feature.

Biological context

Mycobacterium smegmatis is Grahm-positive rod shape bacterium. It is 3 to 5 \(\mu m\) long and around 500 \(nm\) wide. This non-pathogenic species is otften used a biological model to study the pathogenic Mycobacteria such as M.tuberculosis (responsible for the tubercuosis) or M.abscessus, with which it shares the same cell wall structure (Tyagi and Sharma 2002). In particular M.smegmatis has a fast growth (3-4 hours doubling time compared to 24h for M. tuberculosis), allowing for faster experimental protocols.

Here are some know properties of M.smegmatis bacteria :

  • They present variation of cell diameter along their longitudinal axis (Eskandarian et al. 2017). The cell diameter is represented as a height profile along the cell centerline. We respectively name peaks and troughs the local maxima and minima of this profile.

3D image of M.smegmatis. The orange line represents the height profile.
  • They grow following a biphasic and asymetrical polar dynamics (Hannebelle et al. 2020). The cells elongate from the poles, where material is added. After division, the pre-existing pole (OP) elongate at a high rate, whereas the newly created pole (NP) has first a slow growth, and then switches to a fast growth, after the New End Take Off (NETO).

Growth dynamics.

Raw image pre-processing

Data

Several data acquisitions were conducted with wild types and different mutant strains. The raw data is composed of AFM log files times series for each experiments. Each log file contain several images, each one representing a physical channel such as height, stiffness, adhesion etc. After extraction of the data, forward and backward cells are aligned, artefacts such as image scars are detected and corrected.

At each time step, images representing different physical variables are produced by the AFM

Segmentation

At each time steps, images are segmented to detect each cells using the cellpose package (Stringer et al. 2021). If available, different physical channels are combined to improve the segmentation. Forward and backward images are also combined.

Images are combined to improve the segmentation

Here is an example on how to use cellpose on an image. Different models are available (with the seg_mod variable), depending on the training datasets. With cellpose 3, different denoising models are also available (with the denoise_mod variable).

Code
import numpy as np
import matplotlib.pyplot as plt
from cellpose import io, denoise, plot
from PIL import Image


'''
Parameters
'''

image_path = 'raw_img.png'
path_to_save = 'segmented_img'
# Segmentation model type
seg_mod = 'cyto'   
# Denoizing model
denoise_mod = "denoise_cyto3"  
# Expected cell diameter (pixels)
dia = 40
# Type of segmentation (with / without nuclei, different color channels or not)
chan = [0,0] 
# Segmentation sensibility parameters
thres = 0.8
celp = 0.4

'''
Computing segmentation
'''


# Opening image to segment
img=np.array(Image.open(image_path))[:,:,1]

# Chosing a model type :
model = denoise.CellposeDenoiseModel(gpu=False, model_type=seg_mod, restore_type=denoise_mod)

# Computing segmentaion
masks, flows, st, diams = model.eval(img, diameter = dia, channels=chan, flow_threshold = thres, cellprob_threshold=celp)


# Saving the results into a numpy file
io.masks_flows_to_seg(img, masks, flows, path_to_save, channels=chan, diams=diams)

We plot the final results :

Code
plt.imshow(img,cmap='gray')
plt.show()

Raw image
Code
mask_RGB = plot.mask_overlay(img,masks)
plt.imshow(mask_RGB)
plt.show()

Image with segmented masks overlaid

Centerline

Since we are interested in studying the variations of the cell diameter, we define height profile as the value of the cell height along the cell centerline. The cell centerline are computed using a skeletonization algorithm Lee, Kashyap, and Chu (1994). Here is an example of skeletonization

Code
from skimage.morphology import skeletonize

# Selecting first mask
first_mask =  masks == 1

skel_img = skeletonize(first_mask, method='lee')  
skel = np.argwhere(skel_img)
plt.imshow(first_mask, cmap='gray')

plt.scatter(skel[:,1], skel[:,0], 0.5*np.ones(np.shape(skel[:,0])), color='r', marker='.')
plt.show()

Depending on the masks shapes, centerlines may have branches :

Code
from skimage.morphology import skeletonize

# Selecting first mask
first_mask =  masks == 3

skel_img = skeletonize(first_mask)  #, method='lee'
skel = np.argwhere(skel_img)
plt.imshow(first_mask, cmap='gray')

plt.scatter(skel[:,1], skel[:,0], 0.5*np.ones(np.shape(skel[:,0])), color='r', marker='.')
plt.show()

In practice, centerlines are pruned and extended to the cell poles, in order to capture the cell length. Other geometrical properties such as masks centroids or outlines are computed as well.

Final static processing results in real life data. White masks are excluded from the cell tracking algorithm (see part 2). Black dots are cell centroids. The yellow boxes represent artefacts cleaning.

References

Eskandarian, Haig A, Pascal D Odermatt, Joëlle XY Ven, Melanie Hannebelle, Adrian P Nievergelt, Neeraj Dhar, John D McKinney, and Georg E Fantner. 2017. “Division Site Selection Linked to Inherited Cell Surface Wave Troughs in Mycobacteria.” Nature Microbiology 2 (9): 1–6.
Hannebelle, Mélanie, Joëlle XY Ven, Chiara Toniolo, Haig A Eskandarian, Gaëlle Vuaridel-Thurre, John D McKinney, and Georg E Fantner. 2020. “A Biphasic Growth Model for Cell Pole Elongation in Mycobacteria.” Nature Communications 11 (1): 1–10.
Lee, Ta-Chih, Rangasami L Kashyap, and Chong-Nam Chu. 1994. “Building Skeleton Models via 3-d Medial Surface Axis Thinning Algorithms.” CVGIP: Graphical Models and Image Processing 56 (6): 462–78.
Stringer, Carsen, Tim Wang, Michalis Michaelos, and Marius Pachitariu. 2021. “Cellpose: A Generalist Algorithm for Cellular Segmentation.” Nature Methods 18 (1): 100–106.
Tyagi, Jaya Sivaswami, and Deepak Sharma. 2002. “Mycobacterium Smegmatis and Tuberculosis.” Trends in Microbiology 10 (2): 68–69.
Zhang, Tongjie Y, and Ching Y. Suen. 1984. “A Fast Parallel Algorithm for Thinning Digital Patterns.” Communications of the ACM 27 (3): 236–39.