segment-multiwell-plate


Namesegment-multiwell-plate JSON
Version 0.4 PyPI version JSON
download
home_pagehttps://github.com/murraycutforth/segment-multiwell-plate
Summarysegment_multiwell_plate: Automatically divide multi-well plate into separate images of each well
upload_time2024-01-05 20:40:14
maintainer
docs_urlNone
authorMurray Cutforth
requires_python>=3.11
licenseGPL 2.0
keywords multiwell plate segmentation segment screen image analysis bioinformatics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/murraycutforth/segment-multiwell-plate/assets/11088372/43852418-7767-4e7f-aba9-2da69ed3eaad)


## 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. 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](https://github.com/murraycutforth/segment-multiwell-plate/assets/11088372/f65e0ef3-e483-464f-8608-67d44eb4d869)

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}
$$

5. 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.


## Release steps

1. Update version number in `__version__.py`
2. `pipenv run python setup.py sdist bdist_wheel`
3. `pipenv run twine upload dist/*`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/murraycutforth/segment-multiwell-plate",
    "name": "segment-multiwell-plate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "multiwell plate segmentation segment screen image analysis bioinformatics",
    "author": "Murray Cutforth",
    "author_email": "murray.cutforth@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2e/8c/368fe63c09ab1e4e0947c59987e80321e3a5345d27089df01d9c4605866f/segment_multiwell_plate-0.4.tar.gz",
    "platform": null,
    "description": "# Segment Multiwell Plates\n\nThis is an image analysis python package, for automatically segmenting an image of a multiwell plate into an array of\nsub-images. This is useful as part of a pipeline in high-throughput screening experiments.\n\n![segment_multiwell_plate_schematic](https://github.com/murraycutforth/segment-multiwell-plate/assets/11088372/43852418-7767-4e7f-aba9-2da69ed3eaad)\n\n\n## Installation\n\nTo use functions from this package, install into your environment using pip:\n\n`pip install segment-multiwell-plate`\n\nFor a developer install, this repo can be installed with pipenv:\n\n`pipenv install --dev`\n\nThe only code dependencies are `python-3.11`, `numpy`, `scipy`, and `scikit-image`. \n\n\n## Usage\n\nWith defaults:\n\n    img_array = segment_multiwell_plate(image)\n\nImage can either by a 2D or 3D (channel, height, width) numpy array. Adjust resampling spline order and resolution of sub-images:\n\n    img_array = segment_multiwell_plate(image, resampling_order=3, subcell_resolution=32)\n\n Detailed control of algorithm parameters can be obtained by passing extra parameters:\n\n    img_array = segment_multiwell_plate(\n      image,\n      resampling_order=1,\n      subcell_resolution=20,\n      blob_log_kwargs=dict(min_sigma=1, max_sigma=6, num_sigma=7, threshold=0.05, overlap=0.0, exclude_border=1),\n      peak_finder_kwargs=dict(peak_prominence=0.2, width=2, filter_threshold=0.2))\n\nExtra output (the well coordinates, and the peak coordinates, both in image space) can be obtained like:\n\n    img_array, well_coords, i_peak_vals, j_peak_vals = segment_multiwell_plate(image, output_full=True)\n\n\n\n## The Algorithm\n\n1. Use the Laplacian of Gaussians method (implemented in `scikit-image`) to find well centre coordinates\n2. For each of the x- and y- axes in turn:\n\n     a. Project all well centres onto this axis\n  \n     b. Compute a histogram of well centre coordinates\n  \n     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.\nAn example of this histogram is: ![peak_hist_640](https://github.com/murraycutforth/segment-multiwell-plate/assets/11088372/f65e0ef3-e483-464f-8608-67d44eb4d869)\n\n4.  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.\nThe 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\nsystem 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:\n\n$$\n\\begin{bmatrix}\n    1 & 0 \\\\\n    1 & 1 \\\\\n    \\vdots & \\vdots \\\\\n    1 & N-1\n\\end{bmatrix} \\begin{bmatrix}\n    x_0 \\\\\n    \\Delta x\n\\end{bmatrix} = \\begin{bmatrix}\n    \\text{Peak}_1 \\\\\n    \\text{Peak}_2 \\\\\n    \\vdots \\\\\n    \\text{Peak}_N\n\\end{bmatrix}\n$$\n\n5. 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`,\nwhich has options for high order spline interpolation.\n\n \n## TODO\n\n- 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?\n- 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.\n\n\n## Release steps\n\n1. Update version number in `__version__.py`\n2. `pipenv run python setup.py sdist bdist_wheel`\n3. `pipenv run twine upload dist/*`\n",
    "bugtrack_url": null,
    "license": "GPL 2.0",
    "summary": "segment_multiwell_plate: Automatically divide multi-well plate into separate images of each well",
    "version": "0.4",
    "project_urls": {
        "Homepage": "https://github.com/murraycutforth/segment-multiwell-plate"
    },
    "split_keywords": [
        "multiwell",
        "plate",
        "segmentation",
        "segment",
        "screen",
        "image",
        "analysis",
        "bioinformatics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c951fd915dc80aea8ccb4c30c36e150de31e0aa8324900201282735ff4d80dba",
                "md5": "b8c2b3bfbfa153ab4b79f0b793cbeef0",
                "sha256": "9952592660f7e915bb62a6602ec35564e8865457b90bf63c3c4c6f49a7e24e45"
            },
            "downloads": -1,
            "filename": "segment_multiwell_plate-0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8c2b3bfbfa153ab4b79f0b793cbeef0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 10701,
            "upload_time": "2024-01-05T20:40:12",
            "upload_time_iso_8601": "2024-01-05T20:40:12.288904Z",
            "url": "https://files.pythonhosted.org/packages/c9/51/fd915dc80aea8ccb4c30c36e150de31e0aa8324900201282735ff4d80dba/segment_multiwell_plate-0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2e8c368fe63c09ab1e4e0947c59987e80321e3a5345d27089df01d9c4605866f",
                "md5": "24436723b4b330106990acf59430a9bd",
                "sha256": "7a5f06a89992c5dc3072d56cc66b9a713abf063cfe4709e981bcba432c2d018e"
            },
            "downloads": -1,
            "filename": "segment_multiwell_plate-0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "24436723b4b330106990acf59430a9bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 12023,
            "upload_time": "2024-01-05T20:40:14",
            "upload_time_iso_8601": "2024-01-05T20:40:14.235474Z",
            "url": "https://files.pythonhosted.org/packages/2e/8c/368fe63c09ab1e4e0947c59987e80321e3a5345d27089df01d9c4605866f/segment_multiwell_plate-0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-05 20:40:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "murraycutforth",
    "github_project": "segment-multiwell-plate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "segment-multiwell-plate"
}
        
Elapsed time: 0.15918s