Skip to content

infer_subc/organelles/lysosome

fixed_infer_lyso(in_img)

Procedure to infer lyso from linearly unmixed input

Parameters

in_img

a 3d image containing all the channels

Returns

nuclei_object

mask defined extent of NU

Source code in infer_subc/organelles/lysosome.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def fixed_infer_lyso(in_img: np.ndarray) -> np.ndarray:
    """
    Procedure to infer lyso from linearly unmixed input

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

    Returns
    -------------
    nuclei_object:
        mask defined extent of NU
    """
    median_sz = 4
    gauss_sig = 1.34
    dot_scale_1 = 5
    dot_cut_1 = 0.09
    dot_scale_2 = 2.5
    dot_cut_2 = 0.07
    dot_scale_3 = 1
    dot_cut_3 = 0.01
    filament_scale = 1
    filament_cut = 0.15
    min_hole_w = 0
    max_hole_w = 25
    small_obj_w = 3

    return infer_lyso(
        in_img,
        median_sz,
        gauss_sig,
        dot_cut_1,
        dot_scale_1,
        dot_cut_2,
        dot_scale_2,
        dot_cut_3,
        dot_scale_3,
        filament_scale,
        filament_cut,
        min_hole_w,
        max_hole_w,
        small_obj_w,
    )

get_lyso(in_img, meta_dict, out_data_path)

load lyso 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/lysosome.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def get_lyso(in_img: np.ndarray, meta_dict: Dict, out_data_path: Path) -> np.ndarray:
    """
    load lyso 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:
        start = time.time()
        lyso = import_inferred_organelle("lyso", meta_dict, out_data_path)
        end = time.time()
        print(f"loaded lyso in ({(end - start):0.2f}) sec")
    except:
        start = time.time()
        print("starting segmentation...")
        lyso = infer_and_export_lyso(in_img, meta_dict, out_data_path)
        end = time.time()
        print(f"inferred (and exported) lyso in ({(end - start):0.2f}) sec")

    return lyso

infer_and_export_lyso(in_img, meta_dict, out_data_path)

infer lyso and write inferred lyso 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/lysosome.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def infer_and_export_lyso(in_img: np.ndarray, meta_dict: Dict, out_data_path: Path) -> np.ndarray:
    """
    infer lyso and write inferred lyso 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

    """
    lyso = fixed_infer_lyso(in_img)
    out_file_n = export_inferred_organelle(lyso, "lyso", meta_dict, out_data_path)
    print(f"inferred lyso. wrote {out_file_n}")
    return lyso

infer_lyso(in_img, median_sz, gauss_sig, dot_scale_1, dot_cut_1, dot_scale_2, dot_cut_2, dot_scale_3, dot_cut_3, filament_scale, filament_cut, min_hole_w, max_hole_w, small_obj_w)

Procedure to infer lyso 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

dot_scale

scales (log_sigma) for dot filter (1,2, and 3)

dot_cut

threshold for dot filter thresholds (1,2,and 3)

filament_scale

scale (log_sigma) for filament filter

filament_cut

threshold for filament fitered threshold

min_hole_w

hole filling min for nuclei post-processing

max_hole_w

hole filling cutoff for nuclei post-processing

small_obj_w

minimu object size cutoff for nuclei post-processing

Returns

lyso_object

mask defined extent of lyso object

Source code in infer_subc/organelles/lysosome.py
17
18
19
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def infer_lyso(
    in_img: np.ndarray,
    median_sz: int,
    gauss_sig: float,
    dot_scale_1: float,
    dot_cut_1: float,
    dot_scale_2: float,
    dot_cut_2: float,
    dot_scale_3: float,
    dot_cut_3: float,
    filament_scale: float,
    filament_cut: float,
    min_hole_w: int,
    max_hole_w: int,
    small_obj_w: int,
) -> np.ndarray:
    """
    Procedure to infer lyso 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
    dot_scale:
        scales (log_sigma) for dot filter (1,2, and 3)
    dot_cut:
        threshold for dot filter thresholds (1,2,and 3)
    filament_scale:
        scale (log_sigma) for filament filter
    filament_cut:
        threshold for filament fitered threshold
    min_hole_w:
        hole filling min for nuclei post-processing
    max_hole_w:
        hole filling cutoff for nuclei post-processing
    small_obj_w:
        minimu object size cutoff for nuclei post-processing

    Returns
    -------------
    lyso_object:
        mask defined extent of lyso object

    """
    lyso_ch = LYSO_CH
    ###################
    # EXTRACT
    ###################
    lyso = select_channel_from_raw(in_img, lyso_ch)

    ###################
    # PRE_PROCESSING
    ###################
    lyso = scale_and_smooth(lyso, median_sz=median_sz, gauss_sig=gauss_sig)

    ###################
    # CORE_PROCESSING
    ###################
    s2_param = [[dot_scale_1, dot_cut_1], [dot_scale_2, dot_cut_2], [dot_scale_3, dot_cut_3]]
    bw_spot = dot_2d_slice_by_slice_wrapper(lyso, s2_param)

    f2_param = [[filament_scale, filament_cut]]
    bw_filament = filament_2d_wrapper(lyso, f2_param)
    # TODO: consider 3D version to call: aicssegmentation::vesselness3D

    bw = np.logical_or(bw_spot, bw_filament)

    ###################
    # POST_PROCESSING
    ###################
    struct_obj = fill_and_filter_linear_size(bw, hole_min=min_hole_w, hole_max=max_hole_w, min_size=small_obj_w)
    return label_uint16(struct_obj)

lyso_filiment_filter(in_img)

spot filter helper function for lyso (DEPRICATED)

Source code in infer_subc/organelles/lysosome.py
180
181
182
183
184
185
186
def lyso_filiment_filter(in_img: np.ndarray) -> np.ndarray:
    """spot filter helper function for lyso (DEPRICATED)"""
    filament_scale = 1
    filament_cut = 0.15
    f2_param = [[filament_scale, filament_cut]]
    # f2_param = [[1, 0.15]]  # [scale_1, cutoff_1]
    return filament_2d_wrapper(in_img, f2_param)

lyso_spot_filter(in_img)

spot filter helper function for lyso

Source code in infer_subc/organelles/lysosome.py
168
169
170
171
172
173
174
175
176
177
def lyso_spot_filter(in_img: np.ndarray) -> np.ndarray:
    """spot filter helper function for lyso"""
    dot_scale_1 = 5
    dot_cut_1 = 0.09
    dot_scale_2 = 2.5
    dot_cut_2 = 0.07
    dot_scale_3 = 1
    dot_cut_3 = 0.01
    s2_param = [[dot_scale_1, dot_cut_1], [dot_scale_2, dot_cut_2], [dot_scale_3, dot_cut_3]]
    return dot_2d_slice_by_slice_wrapper(in_img, s2_param)