masked_loading
Functions to use masked loading of ROIs before/after processing.
_postprocess_output(*, modified_array, original_array, background)
¶
Postprocess cellpose output, mainly to restore its original background.
NOTE: The pre/post-processing functions and the masked_loading_wrapper are currently meant to work as part of the cellpose_segmentation task, with the plan of then making them more flexible; see https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/340.
PARAMETER | DESCRIPTION |
---|---|
modified_array |
The 3D (ZYX) array with the correct object data and wrong background data.
TYPE:
|
original_array |
The 3D (ZYX) array with the wrong object data and correct background data.
TYPE:
|
background |
The 3D (ZYX) boolean array that defines the background.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
The postprocessed array. |
Source code in fractal_tasks_core/masked_loading.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
_preprocess_input(image_array, *, region, current_label_path, ROI_table_path, ROI_positional_index)
¶
Preprocess a four-dimensional cellpose input.
This involves :
- Loading the masking label array for the appropriate ROI;
- Extracting the appropriate label value from the
ROI_table.obs
dataframe; - Constructing the background mask, where the masking label matches with a specific label value;
- Setting the background of
image_array
to0
; - Loading the array which will be needed in postprocessing to restore background.
NOTE 1: This function relies on V1 of the Fractal table specifications, see https://fractal-analytics-platform.github.io/fractal-tasks-core/tables/.
NOTE 2: The pre/post-processing functions and the masked_loading_wrapper are currently meant to work as part of the cellpose_segmentation task, with the plan of then making them more flexible; see https://github.com/fractal-analytics-platform/fractal-tasks-core/issues/340.
Naming of variables refers to a two-steps labeling, as in "first identify organoids, then look for nuclei inside each organoid") :
"masking"
refers to the labels that are used to identify the object vs background (e.g. the organoid labels); these labels already exist."current"
refers to the labels that are currently being computed in thecellpose_segmentation
task, e.g. the nuclear labels.
PARAMETER | DESCRIPTION |
---|---|
image_array |
The 4D CZYX array with image data for a specific ROI.
TYPE:
|
region |
The ZYX indices of the ROI, in a form like
|
current_label_path |
Path to the image used as current label, in a form
like
TYPE:
|
ROI_table_path |
Path of the AnnData table for the masking-label ROIs;
this is used (together with
TYPE:
|
ROI_positional_index |
Index of the current ROI, which is used to
extract
TYPE:
|
Returns: A tuple with three arrays: the preprocessed image array, the background mask, the current label.
Source code in fractal_tasks_core/masked_loading.py
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 93 94 95 96 97 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
masked_loading_wrapper(*, function, image_array, kwargs=None, use_masks, preprocessing_kwargs=None)
¶
Wrap a function with some pre/post-processing functions
PARAMETER | DESCRIPTION |
---|---|
function |
The callable function to be wrapped.
TYPE:
|
image_array |
The image array to be preprocessed and then used as
positional argument for
TYPE:
|
kwargs |
Keyword arguments for |
use_masks |
If
TYPE:
|
preprocessing_kwargs |
Keyword arguments for the preprocessing function
(see call signature of |
Source code in fractal_tasks_core/masked_loading.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|