Cell width from brightfield images

analysis
microscopy
STORM
Author

Jochem H. Smit

Published

March 24, 2020

How to extract a cell’s radius from brightfield images.

%matplotlib notebook
import matplotlib.pyplot as plt
from colicoords import load, CellPlot, Cell
import colicoords.config as config
Warning: Version number not found.

First we load some cell objects:

cells = load('test_cells.hdf5')
len(cells)
76
cell = Cell(cells[16].data)
print(cell)
<colicoords.cell.Cell object at 0x0000020FF7FD0278>

Lets have a look at one of the cells. Here I’ve chosen cell 16 and re-initialized a new cell object from its data object. The coordinate system is for the newly initialized cell is based on initial guesses from the binary image. This includes the initial guess for the radius of the cell.

fig, (ax1, ax2) = plt.subplots(1,2, figsize=(6, 3))
cp = CellPlot(cell)
cp.imshow('binary', ax=ax1)
cp.plot_outline(ax=ax1)

cp.imshow('brightfield', ax=ax2)
cp.plot_outline(ax=ax2)
<IPython.core.display.Javascript object>

<matplotlib.lines.Line2D at 0x20ff82ca2e8>

We’ll optimize the coordinate system based on the brightfield image. This procedure will make the midline of the cell more closely describe the actual cell, but the value for the cell’s radius isnt optimized in this procedure.

cell.optimize('brightfield')
fig, (ax1, ax2) = plt.subplots(1,2, figsize=(6, 3))
cp = CellPlot(cell)
cp.imshow('binary', ax=ax1)
cp.plot_outline(ax=ax1)

cp.imshow('brightfield', ax=ax2)
cp.plot_outline(ax=ax2)
cp.plot_midline(ax=ax2)
<IPython.core.display.Javascript object>

<matplotlib.lines.Line2D at 0x20ff8363b38>

The radius of the cell can instead be measured with the measure_r function. An image is selected to perform the measurement on, which is typically the brightfield image. The radius is then measured from the radial distribution curve of the image. Three different modes can be selected; ‘min’, ‘mid’ and ‘max’, which refers to where in the curve the radius of the cell is defined.

The three options and their effect on the measured radius is shown below.

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(7, 2.5), )
cp = CellPlot(cell)
cp.imshow('brightfield', ax=ax1)
cp.plot_r_dist(data_name='brightfield', ax=ax2, color='k')

colors = ['g', 'r', 'b']
for c, mode in zip(colors, ['min', 'mid', 'max']):
    cell.measure_r(data_name='brightfield', mode=mode)

    cp.plot_outline(ax=ax1, color=c)
    ax2.axvline(cell.radius * config.cfg.IMG_PIXELSIZE / 1000, color=c)
    
plt.tight_layout()
<IPython.core.display.Javascript object>

The measure_r function can also return the measured value, instead of modifiying the cell’s coordinate system value.

radius = cell.measure_r(data_name='brightfield', mode='mid', in_place=False)
radius

print("The cell's radius is {:.2} pixels or {: .2} μm".format(radius, radius * config.cfg.IMG_PIXELSIZE / 1000))
print("The cell's width is {:.3} pixels or {: .2} μm".format(2*radius, 2*radius * config.cfg.IMG_PIXELSIZE / 1000))
The cell's radius is 6.6 pixels or  0.53 μm
The cell's width is 13.2 pixels or  1.1 μm