Skip to content

infer_subc/organelles/cytoplasm

get_cytoplasm(nuclei_obj, cellmask, meta_dict, out_data_path)

load cytoplasm if it exists, otherwise calculate and write to ome.tif file

Parameters

in_img

a 3d np.ndarray image of the inferred organelle (labels or boolean)

cellmask

a 3d image containing the cellmask object (mask)

meta_dict

dictionary of meta-data (ome)

out_data_path

Path object where tiffs are written to

Returns

exported file name

Source code in infer_subc/organelles/cytoplasm.py
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def get_cytoplasm(nuclei_obj: np.ndarray, cellmask: np.ndarray, meta_dict: Dict, out_data_path: Path) -> np.ndarray:
    """
    load cytoplasm if it exists, otherwise calculate and write to ome.tif file

    Parameters
    ------------
    in_img:
        a 3d  np.ndarray image of the inferred organelle (labels or boolean)
    cellmask:
        a 3d image containing the cellmask object (mask)
    meta_dict:
        dictionary of meta-data (ome)
    out_data_path:
        Path object where tiffs are written to

    Returns
    -------------
    exported file name

    """
    try:
        cytoplasm = import_inferred_organelle("cyto", meta_dict, out_data_path)>0
    except:
        start = time.time()
        print("starting segmentation...")
        cytoplasm = infer_and_export_cytoplasm(nuclei_obj, cellmask, meta_dict, out_data_path)
        end = time.time()
        print(f"inferred cytoplasm in ({(end - start):0.2f}) sec")

    return cytoplasm

infer_and_export_cytoplasm(nuclei_object, cellmask, meta_dict, out_data_path)

infer nucleus and write inferred nuclei to ome.tif file

Parameters

nuclei_object

a 3d image containing the nuclei object

cellmask

a 3d image containing the cellmask object (mask)

meta_dict

dictionary of meta-data (ome)

out_data_path

Path object where tiffs are written to

Returns

exported file name

Source code in infer_subc/organelles/cytoplasm.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def infer_and_export_cytoplasm(
    nuclei_object: np.ndarray, cellmask: np.ndarray, meta_dict: Dict, out_data_path: Path
) -> np.ndarray:
    """
    infer nucleus and write inferred nuclei to ome.tif file

    Parameters
    ------------
    nuclei_object:
        a 3d image containing the nuclei object
    cellmask:
        a 3d image containing the cellmask object (mask)
    meta_dict:
        dictionary of meta-data (ome)
    out_data_path:
        Path object where tiffs are written to

    Returns
    -------------
    exported file name

    """
    cytoplasm = infer_cytoplasm(nuclei_object, cellmask)

    out_file_n = export_inferred_organelle(cytoplasm, "cyto", meta_dict, out_data_path)
    print(f"inferred cytoplasm. wrote {out_file_n}")
    return cytoplasm

infer_cytoplasm(nuclei_object, cellmask, erode_nuclei=True)

Procedure to infer infer from linearly unmixed input. (logical cellmask AND NOT nucleus)

Parameters

nuclei_object

a 3d image containing the nuclei object

cellmask

a 3d image containing the cellmask object (mask)

erode_nuclei

should we erode?

Returns

cytoplasm_mask boolean np.ndarray

Source code in infer_subc/organelles/cytoplasm.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def infer_cytoplasm(nuclei_object: np.ndarray, cellmask: np.ndarray, erode_nuclei: bool = True) -> np.ndarray:
    """
    Procedure to infer infer from linearly unmixed input. (logical cellmask AND NOT nucleus)

    Parameters
    ------------
    nuclei_object:
        a 3d image containing the nuclei object
    cellmask:
        a 3d image containing the cellmask object (mask)
    erode_nuclei:
        should we erode?

    Returns
    -------------
    cytoplasm_mask
        boolean np.ndarray

    """
    nucleus_obj = apply_mask(nuclei_object, cellmask)

    if erode_nuclei:
        cytoplasm_mask = np.logical_xor(cellmask, binary_erosion(nucleus_obj))
    else:
        cytoplasm_mask = np.logical_xor(cellmask, nucleus_obj)

    return cytoplasm_mask