Skip to main content

segment_multiwell_plate: Automatically divide multi-well plate into separate images of each well

Project description

Segment Multiwell Plates

This is an image analysis python package, for automatically segmenting an image of a multiwell plate into an array of sub-images. This is useful as part of a pipeline in high-throughput screening experiments.

segment_multiwell_plate_schematic

Installation

To use functions from this package, install into your environment using pip:

pip install segment-multiwell-plate

For a developer install, this repo can be installed with pipenv:

pipenv install --dev

The only code dependencies are python-3.11, numpy, scipy, and scikit-image.

Usage

With defaults:

img_array = segment_multiwell_plate(image)

Image can either by a 2D or 3D (channel, height, width) numpy array. Adjust resampling spline order and resolution of sub-images:

img_array = segment_multiwell_plate(image, resampling_order=3, subcell_resolution=32)

Detailed control of algorithm parameters can be obtained by passing extra parameters:

img_array = segment_multiwell_plate(
  image,
  resampling_order=1,
  subcell_resolution=20,
  blob_log_kwargs=dict(min_sigma=1, max_sigma=6, num_sigma=7, threshold=0.05, overlap=0.0, exclude_border=1),
  peak_finder_kwargs=dict(peak_prominence=0.2, width=2, filter_threshold=0.2))

Extra output (the well coordinates, and the peak coordinates, both in image space) can be obtained like:

img_array, well_coords, i_peak_vals, j_peak_vals = segment_multiwell_plate(image, output_full=True)

The Algorithm

  1. Use the Laplacian of Gaussians method (implemented in scikit-image) to find well centre coordinates

  2. Rotate the image and well centres so that the well grid is aligned with the coordinate axes. This is done by finding a rotation which minimises the Manhattan (L1) distance between neighbouring well centres.

  3. For each of the x- and y- axes in turn:

    a. Project all well centres onto this axis

    b. Compute a histogram of well centre coordinates

    c. Find peaks in this histogram using scipy.signal.find_peaks() - these correspond to estimated x/y coordinates of cell centres in the grid. However, at this point the estimated cell centres will be slightly irregular. An example of this histogram is: peak_hist_640

  4. A regular 2D Cartesian grid is defined by $x0, \Delta x, N_x$ and $y0, \Delta y, N_y$ - the start point, spacing, and number of cells along each axis. The number of cells is the number of peaks estimated in the previous step. The other two parameters are computed as the solution to an overdetermined (N x 2) linear system fitting a regular grid to the estimated cell centres, where we get the optimal (minimal L2 error) solution using a QR decomposition. For the x-axis, the linear system looks like:

$$ \begin{bmatrix} 1 & 0 \ 1 & 1 \ \vdots & \vdots \ 1 & N-1 \end{bmatrix} \begin{bmatrix} x_0 \ \Delta x \end{bmatrix} = \begin{bmatrix} \text{Peak}_1 \ \text{Peak}_2 \ \vdots \ \text{Peak}_N \end{bmatrix} $$

  1. Finally we partition the original image into an array of sub-images, using this grid. Each sub-image is resampled from the original image using scipy.ndimage.map_coordinates, which has options for high order spline interpolation.

TODO

  • The QR decomposition used in the linear least squares sub-problem could be replaced by an analytic solution, but the runtime is currently bottlenecked by the resampling so there's probably no need.

Release steps

  1. Update version number in __version__.py
  2. pipenv run python setup.py sdist bdist_wheel
  3. pipenv run twine upload dist/* (set username to __token__, and password to pypi API token)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segment_multiwell_plate-0.5.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

segment_multiwell_plate-0.5.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file segment_multiwell_plate-0.5.1.tar.gz.

File metadata

File hashes

Hashes for segment_multiwell_plate-0.5.1.tar.gz
Algorithm Hash digest
SHA256 06c3957121b317d0c7fea5f69c332cbfd50ad2c71371029ad2b8004d59cee8e9
MD5 9036cfa96b99f8c79afe001d1e587c07
BLAKE2b-256 38ebb5fb20351ab5ad1d15c7fe08bbbef28ee25e8b46e08505e4ee9aa688cb84

See more details on using hashes here.

File details

Details for the file segment_multiwell_plate-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for segment_multiwell_plate-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86b62fea97e92e234f6e6e144dc87fd95a5158e65ae81d9bcf24263bbed53118
MD5 4aa552ff82ff99e17e3174f275fe6447
BLAKE2b-256 03d44a32c1dd1a965ef23ab741439148ff63432f7514d23db6af27ca4222bfa9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page