MN UNet segmenter
A package for segmenting micronuclei in micrographs.
Quick-start
from mnfinder import MNClassifier
import numpy as np
from tifffile import TiffFile
trained_model = MNClassifier.get_model()
image = TiffFile.imread('path/to/image.tiff').asarray()
labels = trained_model.predict(image)
Installation
MNFinder depends on TensorFlow. It will be installed for you via pip.
pip
pip install mnfinder
Usage
Loading a model
trained_model = MNModel.get_model([model_name])
MNFinder supports several different trained models with different architectures. The default is an Attention U-Net.
Weights will be automatically downloaded.
Available models
Attention
The default network is an Attention U-Net that was trained on 128x128 crops.
Defaults
skip_opening:Falseexpand_masks:Trueuse_argmax:Trueopening_radius: 1
MSAttention
This is a modification of the Attention U-Net that incorporates a multi-scale convolution in the down blocks.
Defaults
skip_opening:Falseexpand_masks:Trueuse_argmax:Trueopening_radius: 1
Combined
An Attention U-Net trained on the micronucleus output of Attention and MSAttention.
Defaults
skip_opening:Falseexpand_masks:Trueuse_argmax:Trueopening_radius: 1
LaplaceDeconstruction
Images are first transformed into Laplace pyramids, and recombined only using the top 2 levels of the pyramid to highlight cell edges.
Defaults
skip_opening:Falseexpand_masks:Trueuse_argmax:Falseopening_radius: 2
Predictions
img = np.array(Image.open("my/image.png"))
labels = trained_model.predict(img, skip_opening=[bool], expand_masks=[bool], use_argmax=[bool], area_thresh=[int], return_raw_output=[bool])
A single method is used to predict and label nuclear and micronucler segments.
These neural nets were trained on images taken at 20x. Predictions for micrographs taken at other resolutions are greatly improved if they are scaled to match a 20x resolution.
Images of arbitrary size will be cropped by a sliding window and segments combined.
Labels are returned as a 3-channel image. Channel 1 contains the unique cell label for each segmented nucleus; channel 2 has each micronucleus labelled with its corresponding cell label; channel 3 has a unique label for each micronucleus.
Optional parameters
skip_opening=bool
: Whether to skip running opening on MN predictions prior to labelling. Many models are improved by removing small 1- or 2-px segments by image opening—erosion following by dilation. Defaults to the model default.
expand_masks=bool
: Whether to expand micronucleus masks by returning the convex hulls of each segment. Defaults to the model default.
use_argmax=bool
: Whether to determine pixel classes by taking the maximum probability. Some models are improved by instead setting a simple threshold on the micronucleus class probability, setting a pixel to the micronucleus class even if the model’s nucleus class probability is higher. If use_argmax is False, the model will select pixels with a background class > model.bg_max and a micronucleus class < model.fg_min. Defaults to the model default.
area_thresh=int|False
: Large micronuclei separated from the nucleus are often classed as nuclei. Any nucleus segments < area_thresh will be converted to micronuclei. Set this to False to skip this conversion. Defaults to 250.
return_raw_output=bool
: If you wish to examine the fields returned by the semantic and instance classifier neural nets, set this to True.
Prediction info
mn_df, nuc_df = MNClassifier.get_label_data(labels)
Provides some basic information about each MN and nuclear label predicted.
Metadata
Release files for mnfinder 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mnfinder-1.2.3.tar.gz | 69.4 MB | Without provenance | Details for mnfinder-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mnfinder-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for mnfinder-1.2.3-py3-none-any.whl |
Total release size: 137.7 MB
Release files / mnfinder-1.2.3.tar.gz
| Download URL | mnfinder-1.2.3.tar.gz |
|---|---|
| Size | 69.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcd39f5e84972496af12058738b13c627e89a41376e17a168d6c0ff58fa09b32
|
|
BLAKE2b-256 checksum How to use checksums |
3d0c96cb7d849ad8e6d7c6aaf09d4298b0670fbaf60823b12d98dbe6a4adfcf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.20
|
Release files / mnfinder-1.2.3-py3-none-any.whl
| Download URL | mnfinder-1.2.3-py3-none-any.whl |
|---|---|
| Size | 68.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11b1f6aea9f40b4dd3cf6c3de30ef8d517a4833907b88b86ce2b7ab1f9dbce4a
|
|
BLAKE2b-256 checksum How to use checksums |
c6a40be44dc1da46500ba6d4449c704a4132c0bf56792cf68d5582928f9191b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.20
|
Security for mnfinder 1.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.