neuralib.segmentation.cellpose.core

class neuralib.segmentation.cellpose.core.AbstractSegmentationOption[source]
DESCRIPTION: str = 'ABC for cellular segmentation'

parser description.

EX_GROUP_SOURCE = 'EX_GROUP_SOURCE'
file: Path

image file path

directory: Path

images directory for batch processing

directory_suffix: str

suffix in batch mode

save_ij_roi: bool

if save also the imageJ/Fiji compatible .roi file

force_re_eval: bool

force re-evaluate the result

model: str

which pretrained model

no_normalize: bool

NOT DO Percentile-based image normalization for eval

napari_view: bool

view in napari

post_parsing()[source]

check args is valid

property file_mode: bool

Flag file mode

property batch_mode: bool

Flag batch mode

raw_image()[source]

Load image from file and convert to grayscale

Returns:

Array[float, [H, W]]

Return type:

ndarray

normalize_image()[source]

Normalize the image

Returns:

Array[float, [H, W]]

Return type:

ndarray

foreach_raw_image()[source]

Load image from a directory and convert to grayscale

Returns:

Tuple of filepath and image Array[float, [H, W]]

Return type:

Iterable[tuple[Path, ndarray]]

foreach_normalize_image()[source]

Normalize the image in batch mode

Returns:

Tuple of filepath and image Array[float, [H, W]]

Return type:

Iterable[tuple[Path, ndarray]]

abstract seg_output(filepath)[source]

Get segmented output save path

Parameters:

filepath (Path) – filepath for image

Returns:

segmented output save path

Return type:

Path

ij_roi_output(filepath)[source]

Get imageJ/Fiji .roi output save path

Parameters:

filepath (Path) – filepath for image

Returns:

ij roi output save path

Return type:

Path

abstract eval()[source]

eval the model in single file or batch files, and save the results

Return type:

None

abstract launch_napari(**kwargs)[source]

napari viewer

class neuralib.segmentation.cellpose.core.AbstractCellPoseOption[source]
DESCRIPTION: str = 'ABC for GUI Cellpose'

parser description.

model: Literal['cyto', 'cyto2', 'cyto3']

which pretrained model

chan_seg: int

channel for segmentation default:{‘none’: -1, ‘gray’: 0, ‘red’: 1, ‘green’: 2, ‘blue’: 3}

chan_nuclear: int

nuclear channel

diameter: int

diameter for each neuron (number of each pixel)

cellpose_view: bool

launch cellpose gui for the analyzed result

seg_output(filepath)[source]

Get segmented output save path

Parameters:

filepath (Path) – filepath for image

Returns:

segmented output save path

Return type:

Path

launch_napari()[source]

napari viewer

launch_cellpose_gui()[source]

AttributeError: ‘MainW’ object has no attribute ‘load_3D’. Cellpose version 3.0.10.

TODO open issue in cellpose -> move load_3D instance attribute to line above io._load_image() in MainW.__init__()

final class neuralib.segmentation.cellpose.core.CellPoseEvalResult[source]

Cellpose results

Dimension parameters:

N = Number of segmented cell

W = Image width

H = Image height

filename: str

image file name

image: ndarray | list[ndarray]

image array

diameter: float

neuronal diameter

chan_choose: list[int]

[chan_seg, chan_nuclear]

masks: ndarray

each pixel in the image is assigned to an ROI (H, W) list of 2D arrays, labelled image, where 0=no masks; 1,2,…=mask labels

flows: list[ndarray]

flows[0] is XY flow in RGB, flows[1] is the cell probability in range 0-255 instead of 0.0 to 1.0, flows[2] is Z flow in range 0-255 (if it exists, otherwise zeros), flows[3] is [dY, dX, cellprob] (or [dZ, dY, dX, cellprob] for 3D), flows[4] is pixel destinations (for internal use)

styles: list[ndarray]

list of 1D arrays of length 256, style vector summarizing each image, also used to estimate size of objects in image

colors: ndarray | None

colors for ROIs (N, 3)

manual_changes: list[Any] | None
est_diam: float | None

estimated diameter (if run on command line)

model_path: int
flow_threshold: float | None
cellprob_threshold: float
normalize_params: NormParams | None
img_restore: list[ndarray] | None
restore: str | None
ratio: float
__init__(filename, image, diameter, chan_choose, masks, flows=NOTHING, styles=NOTHING, *, colors=None, manual_changes=None, est_diam=None, model_path=0, flow_threshold=None, cellprob_threshold=0, normalize_params=None, img_restore=None, restore=None, ratio=1.0, outlines=array([], dtype=float64), ismanual=array([], dtype=float64))

Method generated by attrs for class CellPoseEvalResult.

Parameters:
  • filename (str)

  • image (ndarray | list[ndarray])

  • diameter (float)

  • chan_choose (list[int])

  • masks (ndarray)

  • flows (list[ndarray])

  • styles (list[ndarray])

  • colors (ndarray | None)

  • manual_changes (list[Any] | None)

  • est_diam (float | None)

  • model_path (int)

  • flow_threshold (float | None)

  • cellprob_threshold (float)

  • normalize_params (NormParams | None)

  • img_restore (list[ndarray] | None)

  • restore (str | None)

  • ratio (float)

  • outlines (ndarray)

  • ismanual (ndarray)

Return type:

None

outlines: ndarray

outlines of ROIs. Array[uint16, [H, W]]

ismanual: ndarray

whether or not mask k was manually drawn or computed by the cellpose algorithm. Array[bool, N]

classmethod load(seg_file)[source]
Parameters:

seg_file (str | Path | bytes | BinaryIO | BufferedIOBase | BufferedReader)

Return type:

Self

save_seg_file(image_file)[source]

Save as seg.npy file`

Parameters:

image_file (str)

Return type:

None

save_roi(output_file)[source]

Save as imageJ .roi file. CHECKOUT native BUG: https://github.com/MouseLand/cellpose/issues/969

Parameters:

output_file (str | Path | bytes | BinaryIO | BufferedIOBase | BufferedReader)

Return type:

None

nan_masks()[source]

value 0 in masks to nan

Return type:

ndarray

nan_outlines()[source]

value 0 in outlines to nan

Return type:

ndarray

property points: ndarray

Calculate center of each segmented area in pixel. Array[int, N]