spacr.qt.organelle_modes¶
Organelle detection’s methods, offered to Make Masks as magnifier modes.
spaCR already implements eight ways of finding an object – otsu,
adaptive, log, dog, ridge, hysteresis, cellpose and
unet – in spacr.object.generate_organelle_masks_sam(). Make Masks
offered two of them. A curator correcting a mask of tubules had Otsu and
Cellpose; the ridge filter that would have found the tubules was three
screens away, in a batch pipeline, and could not be tried on the field in
front of them.
THIS MODULE IS A BRIDGE AND NOT A SECOND IMPLEMENTATION. Every classical
method runs through spacr.object._segment_single_image(), the one the
organelle pipeline’s workers call, and unet through
spacr.object._segment_unet(). So “adaptive” means in Make Masks
exactly what it means in a mask run, and a curator who tunes a block size
on one field is tuning the setting the pipeline will read. The whole of
this module’s own work is naming the parameters, turning them into the
organelle_* keys that engine reads, and saying what each method suits.
WHICH MORPHOLOGY A MODE RUNS UNDER. The organelle engine dispatches on
organelle_morphology FIRST and the method second, because the same word
means different code for different shapes. Make Masks has no morphology
box – a curator picks a detector, not a cell-biology category – so each
mode names the morphology whose branch implements that method in the form
a curator of whole objects wants, and MODE_MORPHOLOGY is that
choice written down:
adaptiveruns underirregular: the branch that smooths, closes, opens, fills holes and watershed-splits, which is what a solid object wants. Thespotsbranch’s adaptive is a top-hat filter first and erases anything wider than its disk.loganddogrun underspots, the only branch that has them.ridge,hysteresisandunetrun undernetwork, likewise.
spacr.organelle_types.LEGAL_METHODS remains the statement of which
method is legal for which shape, and guidance() reads the sentence
each mode shows straight out of it rather than restating it here.
Classes¶
Every parameter the organelle methods read, as one hashable value. |
Functions¶
|
What this method suits, from |
|
Every mode this module adds to Make Masks, in the box's order. |
|
|
|
The parameters this mode actually read, for a mask's ledger entry. |
|
Detect objects in |
Module Contents¶
- class spacr.qt.organelle_modes.MethodParams[source]¶
Bases:
NamedTupleEvery parameter the organelle methods read, as one hashable value.
One tuple rather than one per method, because it goes into the magnifier’s request key: a request carries every setting a detector could read, so a mode that falls back to another still finds its own settings in it. The defaults are
spacr.settings._set_organelle_defaults()’, so a method means the same thing here as it does in a mask run until somebody moves a box.- Parameters:
adaptive_block – the local threshold’s window, in pixels, forced odd by the engine. Read by
adaptiveand byridgewhen its threshold is adaptive.adaptive_offset – subtracted from the Gaussian-weighted local mean before the bright-foreground comparison. Increasing it lowers the threshold and admits more pixels before cleanup; a negative offset raises the threshold. Units are those of the processed detector image: smoothed image intensity for
adaptive, ridge response forridgewith an adaptive threshold. Default 5.0; an offset suitable for raw intensities can overwhelm a response whose values lie between 0 and 1.morph_radius – the cleanup disk, in pixels.
adaptivealso pre-smooths with half of it; the network branches close with half.fill_holes – holes up to this area, in square pixels, are filled.
adaptiveonly.watershed_spots – whether
loganddoggrow a watershed from each blob centre rather than stamping a disk.log_min_sigma – smallest Gaussian scale LoG searches, in pixels; a blob’s radius is about sigma times root two.
log_max_sigma – the largest.
log_num_sigma – how many scales between the two.
log_threshold – the blob-response cut-off, read by
logAND bydog, which has no threshold of its own.dog_sigma_low – DoG’s smallest scale, in pixels.
dog_sigma_high – DoG’s largest.
ridge_filter –
frangi,satoormeijering.ridge_sigmas – the filament half-widths to look for, in pixels.
ridge_threshold –
otsuoradaptive, how the ridge response is cut.skeletonize – reduce a network to a one-pixel skeleton and label that, so area measures length rather than thickness.
hysteresis_low – the weak level; under 1.0 it is read as a fraction and becomes that percentile of the smoothed image.
hysteresis_high – the seeding level, read the same way.
unet_model_path – the
.pt/.pthfile to load.unet_threshold – the probability the sigmoid output is cut at.
- spacr.qt.organelle_modes.guidance(mode: str) str[source]¶
What this method suits, from
spacr.organelle_types.The sentence is built from
spacr.organelle_types.LEGAL_METHODS, which is where spaCR already records which method belongs to which shape, so a method that gains or loses a shape there gains or loses it here too rather than drifting into a second opinion.- Parameters:
mode – one of
modes(), or any organelle method name.- Returns:
an English sentence, not yet translated: a caller showing it passes it through
tr.
- spacr.qt.organelle_modes.modes() Tuple[str, ...][source]¶
Every mode this module adds to Make Masks, in the box’s order.
- spacr.qt.organelle_modes.organelle_settings(mode: str, params: MethodParams, min_area: int = 0) Dict[str, object][source]¶
paramsas theorganelle_*keys the engine reads.- Parameters:
mode – one of
modes().params – the parameters as the screen holds them.
min_area – the smallest object to keep, in pixels – Make Masks’ own Min area, so one number governs the magnifier, the detect buttons and the Remove-small button.
- Returns:
a dict for
spacr.object._segment_single_image().- Raises:
KeyError – for a mode this module does not add.
- spacr.qt.organelle_modes.provenance(mode: str, params: MethodParams) Dict[str, object][source]¶
The parameters this mode actually read, for a mask’s ledger entry.
A mode’s own parameters and no others, so an entry says what the detection was told rather than carrying nineteen numbers eighteen of which no branch looked at.
- Parameters:
mode – one of
modes(), or any other magnifier mode, which reads nothing here and records nothing.params – the parameters the detection ran with.
- Returns:
{field: value}, JSON-safe; empty for a mode that is not one of this module’s.
- spacr.qt.organelle_modes.segment(image: numpy.ndarray, mode: str, params: MethodParams, min_area: int = 0, model=None) numpy.ndarray[source]¶
Detect objects in
imagethe way organelle detection would.- Parameters:
image – a 2-D field or region. Read, never modified.
mode – one of
modes().params – the parameters the method reads.
min_area – the smallest object to keep, in pixels.
model – a loaded U-Net, for
unet; loaded fromMethodParams.unet_model_pathwhen not given.
- Returns:
a 2-D label image the shape of
image.- Raises:
KeyError – for a mode this module does not add.
ValueError – from the engine, for a parameter it refuses – an unknown ridge filter, a U-Net path that is not a file.