Skip to content

infer_subc/organelles/mitochondria

fixed_infer_mito(in_img)

Procedure to infer mitochondria from linearly unmixed input

Parameters

in_img

a 3d image containing all the channels

Returns

mito_object mask defined extent of mitochondria

Source code in infer_subc/organelles/mitochondria.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def fixed_infer_mito(in_img: np.ndarray) -> np.ndarray:
    """
    Procedure to infer mitochondria from linearly unmixed input

    Parameters
    ------------
    in_img:
        a 3d image containing all the channels

    Returns
    -------------
    mito_object
        mask defined extent of mitochondria
    """
    median_sz = 3
    gauss_sig = 1.4
    vesselness_scale = 1.5
    vesselness_cut = 0.05
    small_obj_w = 3

    return infer_mito(in_img, median_sz, gauss_sig, vesselness_scale, vesselness_cut, small_obj_w)

get_mito(in_img, meta_dict, out_data_path)

load mitochondria 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)

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/mitochondria.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def get_mito(in_img: np.ndarray, meta_dict: Dict, out_data_path: Path) -> np.ndarray:
    """
    load mitochondria 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)
    meta_dict:
        dictionary of meta-data (ome)
    out_data_path:
        Path object where tiffs are written to

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

    """

    try:
        mitochondria = import_inferred_organelle("mito", meta_dict, out_data_path)
    except:
        start = time.time()
        print("starting segmentation...")
        mitochondria = infer_and_export_mito(in_img, meta_dict, out_data_path)
        end = time.time()
        print(f"inferred (and exported) mitochondria in ({(end - start):0.2f}) sec")

    return mitochondria

infer_and_export_mito(in_img, meta_dict, out_data_path)

infer mitochondria and write inferred mitochondria to ome.tif file

Parameters

in_img

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

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/mitochondria.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def infer_and_export_mito(in_img: np.ndarray, meta_dict: Dict, out_data_path: Path) -> np.ndarray:
    """
    infer mitochondria and write inferred mitochondria to ome.tif file

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

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

    """
    mitochondria = fixed_infer_mito(in_img)
    out_file_n = export_inferred_organelle(mitochondria, "mito", meta_dict, out_data_path)
    print(f"inferred mitochondria. wrote {out_file_n}")
    return mitochondria

infer_mito(in_img, median_sz, gauss_sig, vesselness_scale, vesselness_cut, small_obj_w)

Procedure to infer mitochondria from linearly unmixed input.

Parameters

in_img

a 3d image containing all the channels

median_sz

width of median filter for signal

gauss_sig

sigma for gaussian smoothing of signal

vesselness_scale

scale (log_sigma) for vesselness filter

vesselness_cut

threshold for vesselness fitered threshold

small_obj_w

minimu object size cutoff for nuclei post-processing

Returns

mito_object mask defined extent of mitochondria

Source code in infer_subc/organelles/mitochondria.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
70
71
72
def infer_mito(
    in_img: np.ndarray,
    median_sz: int,
    gauss_sig: float,
    vesselness_scale: float,
    vesselness_cut: float,
    small_obj_w: int,
) -> np.ndarray:
    """
    Procedure to infer mitochondria from linearly unmixed input.

    Parameters
    ------------
    in_img:
        a 3d image containing all the channels
    median_sz:
        width of median filter for signal
    gauss_sig:
        sigma for gaussian smoothing of  signal
    vesselness_scale:
        scale (log_sigma) for vesselness filter
    vesselness_cut:
        threshold for vesselness fitered threshold
    small_obj_w:
        minimu object size cutoff for nuclei post-processing

    Returns
    -------------
    mito_object
        mask defined extent of mitochondria
    """
    mito_ch = MITO_CH
    ###################
    # EXTRACT
    ###################
    mito = select_channel_from_raw(in_img, MITO_CH)

    ###################
    # PRE_PROCESSING
    ###################
    struct_img = scale_and_smooth(mito, median_sz=median_sz, gauss_sig=gauss_sig)

    ###################
    # CORE_PROCESSING
    ###################
    struct_img = vesselness_slice_by_slice(struct_img, sigma=vesselness_scale, cutoff=vesselness_cut, tau=0.75)

    ###################
    # POST_PROCESSING
    ###################
    struct_obj = size_filter_linear_size(struct_img, min_size=small_obj_w)

    return label_uint16(struct_obj)