Image segmentation and signal quantification for 2D objects
Authors/Creators
Description
Using OpenCV, Scipy and Scikit Image in Python scripting, you will be able to quickly segment thousands of cells and extract intensity data for statistical analysis.
This is a two-part Python script on how to segment images obtained from a life science experiment, although for real-life images of objects with a clearly defined background and not too much noise, it can function also. The images were generated in Photoshop instead of lab microscopes, in as close to the real thing as possible. Only a control and a test set were used for simplicity.
This script is written in Python, with a mix of imaging tools including OpenCV, Scipy and Scikit Image. The script assumes you have, in one master folder, two or more folders where you store control and test image sets. Here, in our example, there are 4 images in each folder, each image with more than 10 cells, providing a decent statistical power. The images should have at least two channels, in this case, green and red, representing fluorescent markers. The imagined scenario is that the red channel is relatively constant across all cells and conditions, and the green signal varies as a consequence of some chemical treatment. The experimenter would like to see if the green signal is amplified or decreased.
The script contains two phases:
A. Cell segmentation - cells are extracted in individual images and stored in their experimental folder together.
B. Image analysis - each cell is scanned for the mean green intensity normalized to the red channel, giving the experimenter the statistical results.
The inputs will be images with black backgrounds and separate color channels for red, green and/or blue:
The images should have as little noise as possible for this script to work well, for reasons that will be explained below, and of course not be over-saturated, to properly compare the signal intensities between image sets.
The outputs will be, for the two phases: <br >
A. Cell segmentation:
1. Masks - simplified images of the original, for each image. They are produced using Otsu thresholding, and are used to separate individual cells from the original images.
2. Split images - for each cell, an image with the original size but only one cell visible.
3. Cropped images - from each split image, a single cell is cropped by drawing a box around its extremities, and all black signal is subtracted, leaving only the color ranges for the markers inside that cell.
An important note on input images: The background should be kept to a minimum by selecting out the noise in the microscope settings. That is because the program will count the small pixels as blobs to count, which slows down the scanning process.
B. Image analysis:
1. A single csv - statistics on data.csv - it contains data on minimum, mode and maximum values of pixel intensity for each channel, as well as the green mean intensity normalized to the red channel mean. The latter is used for the graphic statistical output.<br >
2. A single image (outputs.png) with the violin plot of green mean intensities for the two experimental conditions. <br>
Image processing takes place in the following way:
1. The RGB image channels are split and stored as numpy arrays.
2. Histograms are calculated for each channel. Here are some possible scenarios (visualization is possible inside the script)
3. Means are calculated for the histograms.
4. The green histogram mean intensity is normalized to the red histogram mean intensity.
5. Mean green intensities are compared between datasets.
The principle behind normalization is that experimental setup (cell position on slide or inside the focal field of the image) can alter the green color channel (of interest here), and the red channel can serve as a standard for correction. The channel-corrected mean now can be used to accurately determine if the chemical added to the experimental condition 1 or 2 had an effect. The statistics (like t-test) are not included here but can be easily added or created using the statistics csv generated.
Files
Image-segmentation-and-signal-quantification-for-2D-objects--in-science-.zip
Files
(9.2 MB)
| Name | Size | Download all |
|---|---|---|
|
md5:ada901a374874cbd2801345480f97fbe
|
9.2 MB | Preview Download |