Microscopy image segmentation for area measurement
Tool to measure area in microscopy sampels. E.g. measure background and cell. Can be trained to recognize multiple different area types. Uses a method akin to gaussian mixture models. This is a quick hack for now.
Python, numpy, scipy, scikit image and others.
Windows and MacOSX users can install Anaconda to get all required dependencies: http://www.anaconda.com/
David R. Piegdon firstname.lastname@example.org
All files in this repository are released unter the GNU General Public License Version 3 or later.
Segmenting a bunch of images is a 3-step process, with an optional fourth step:
preprocess: Images need to be preprocessed. (NOTE: Expected are
tifimages as input)
train: The user needs to define models. After that The script will derive a statistical model from these.
apply: The models are applied to all images. Review your results!
reapply: You can edit the
..._segmentation.pngfiles and call
reapplyto change the segmentation results as done in the third step.
After that you can take the machine-readable results from the
Check out the git repository somewhere. Alternatively, put
assetssubdirectory with all its files into a directory, e.g.
tifimages to be processed into a directory inside this repository/directory, e.g.
Open a shell (/terminal/command prompt) and go to the
python ./segmentation.py preprocess data.
For all models that you want to separate, create a subdirectory inside
model_xyz, where the prefix MUST be
model_and the suffix is named by you. e.g. two models
For each model that you want to create, pick some pictures from the PREPROCESSED images (in
repo/data/*_preprocessed.png) and mask everything but the model-relevant areas. Save them as PNG to
repo/data/model_background. E.g. remove everything but the background and save those into
repo/model_background, same for foreground, or any other models that you wanted to define. You CAN use the alpha channel. Everything that is NOT FULLY OPAQUE will be ignored when generating the model.
Again in the shell in the directory
python ./segmentation.py train data. This will learn the models that you defined.
When the learning is finished, in the same shell, run
python ./segmentation.py apply data
Quickly review all
..._analysis.pngfiles. If you find a bad segmentation, you have two choices:
a) Improve the models that you defined and go back to the
trainstep. That will result in a different interpretation for all of your images.
b) Manually edit the segmentation of a specific image. To do so, edit the specific
..._segmentation.pngfile. You MUST stick to the colors used for the different layers. No transparency and no gradients are allowed. When you are done, call
python ./segmentation.py reapply data. The important bit here is to REapply, or your edit will be overwritten. This obviously only changes the segmentation you edited.
For further analysis use the
analysis-summary.csvfile. It contains the amount of pixels and area in percent for each model for each file, in a machine-readable way. E.g., you can open this with Excel.
Get a beer and enjoy.
In the end, the directory should look like:
repo/ repo/segmentation.py << Script to run. repo/__init__.py << Part of the script. repo/assets/* << Part of the script. repo/data/ << Directory where you place your data repo/data/originalimage1.tif << original image files repo/data/originalimage2.tif repo/data/originalimage3.tif repo/data/originalimage1_preprocessed.png << Preprocessed images generated by preprocess command. repo/data/originalimage2_preprocessed.png repo/data/originalimage3_preprocessed.png repo/data/model_front/sample1.png << Samples that you cut out from preprocessed repo/data/model_front/sample2.png images to define models. repo/data/model_front/sample3.png repo/data/model_back/sample1.png << Samples for other model group. repo/data/model_back/sample2.png repo/data/model_back/sample3.png repo/data/model_front.gmmpickle << Raw data of model, as generated by `train` works. repo/data/model_back.gmmpickle You should ignore this. repo/data/originalimage1_analysis.png << Segmentation, as generated by apply command. repo/data/originalimage2_analysis.png Can optionally be edited and reapplied. repo/data/originalimage3_analysis.png repo/data/originalimage1_segmentation.png << Analysis files for review, repo/data/originalimage2_segmentation.png as generated by apply command. repo/data/originalimage3_segmentation.png repo/data/analysis-summary.csv << CSV containing final analysis per model per image.