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.
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
-
Use the Laplacian of Gaussians method (implemented in
scikit-image
) to find well centre coordinates -
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: -
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} $$
- 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 method currently assumes that the array of wells is aligned with the image axes, future work could relax this assumption by implementing a rotation finding step, perhaps optimising the entropy of the histogram?
- 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.
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
Built Distribution
File details
Details for the file segment_multiwell_plate-0.3.tar.gz
.
File metadata
- Download URL: segment_multiwell_plate-0.3.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d69fccd2d162da514bbc76c49b4cb9f1bba63105050ad6e75198a2c1c8ce0fa9 |
|
MD5 | 454a456a7354115ff2595c1c5e22ce98 |
|
BLAKE2b-256 | 6ee424fb23ba1852047b2adf99dc90b441be9a382a090a2565bb25b527f85706 |
File details
Details for the file segment_multiwell_plate-0.3-py3-none-any.whl
.
File metadata
- Download URL: segment_multiwell_plate-0.3-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b498e854a22357266f3ccbfdd54f6eecc9a7db8c6addd1c6924446eae84bd8c |
|
MD5 | 3d53a6934f8583e6e06d87b47219a1d9 |
|
BLAKE2b-256 | 79b1f1552ecce25f9cb3676ccd2519e213ed0e70d85abb468391d7701d85cbfe |