napari_cellseg3d.code_models.crf
Implements the CRF post-processing step for WNet3D.
The CRF requires the following parameters:
- images : Array of shape (N, C, H, W, D) containing the input images.
- predictions: Array of shape (N, K, H, W, D) containing the predicted class probabilities for each pixel.
- sa: alpha standard deviation, the scale of the spatial part of the appearance/bilateral kernel.
- sb: beta standard deviation, the scale of the color part of the appearance/bilateral kernel.
- sg: gamma standard deviation, the scale of the smoothness/gaussian kernel.
- w1: weight of the appearance/bilateral kernel.
- w2: weight of the smoothness/gaussian kernel.
Inspired by https://arxiv.org/abs/1606.00915 and https://arxiv.org/abs/1711.08506. Also uses research from: Efficient Inference in Fully Connected CRFs with Gaussian Edge Potentials Philipp Krähenbühl and Vladlen Koltun NIPS 2011
Implemented using the pydensecrf library available at https://github.com/lucasb-eyer/pydensecrf. However, this is not maintained, thus we maintain this pacakge at https://github.com/AdaptiveMotorControlLab/pydensecrf.
Classes:
| Name | Description |
|---|---|
CRFWorker |
Worker for the CRF post-processing step for the WNet3D. |
Functions:
| Name | Description |
|---|---|
correct_shape_for_crf |
Corrects the shape of the image to be compatible with the CRF post-processing step. |
crf |
Implements the CRF post-processing step for the WNet3D. |
crf_batch |
CRF post-processing step for the WNet3D, applied to a batch of images. |
crf_with_config |
Implements the CRF post-processing step for the WNet3D. |
CRFWorker
Bases: GeneratorWorker
Worker for the CRF post-processing step for the WNet3D.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the CRFWorker. |
Source code in napari_cellseg3d/code_models/crf.py
178 179 180 181 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 210 211 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 | |
__init__
__init__(images_list: list, labels_list: list, config: CRFConfig = None, log=None)
Initializes the CRFWorker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_list
|
list
|
List of images to process. |
required |
labels_list
|
list
|
List of labels to process. |
required |
config
|
CRFConfig
|
Configuration for the CRF post-processing step. Defaults to None. |
None
|
log
|
function
|
Logging function. Defaults to None. |
None
|
Source code in napari_cellseg3d/code_models/crf.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
correct_shape_for_crf
correct_shape_for_crf(image, desired_dims=4)
Corrects the shape of the image to be compatible with the CRF post-processing step.
Source code in napari_cellseg3d/code_models/crf.py
42 43 44 45 46 47 48 49 50 51 | |
crf
crf(image, prob, sa, sb, sg, w1, w2, n_iter=5)
Implements the CRF post-processing step for the WNet3D.
Inspired by https://arxiv.org/abs/1210.5644, https://arxiv.org/abs/1606.00915 and https://arxiv.org/abs/1711.08506. Implemented using the pydensecrf library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Array of shape (C, H, W, D) containing the input image. |
required |
prob
|
ndarray
|
Array of shape (K, H, W, D) containing the predicted class probabilities for each pixel. |
required |
sa
|
float
|
alpha standard deviation, the scale of the spatial part of the appearance/bilateral kernel. |
required |
sb
|
float
|
beta standard deviation, the scale of the color part of the appearance/bilateral kernel. |
required |
sg
|
float
|
gamma standard deviation, the scale of the smoothness/gaussian kernel. |
required |
w1
|
float
|
weight of the appearance/bilateral kernel. |
required |
w2
|
float
|
weight of the smoothness/gaussian kernel. |
required |
n_iter
|
int
|
Number of iterations for the CRF post-processing step. Defaults to 5. |
5
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of shape (K, H, W, D) containing the refined class probabilities for each pixel. |
Source code in napari_cellseg3d/code_models/crf.py
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 | |
crf_batch
crf_batch(images, probs, sa, sb, sg, w1, w2, n_iter=5)
CRF post-processing step for the WNet3D, applied to a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ndarray
|
Array of shape (N, C, H, W, D) containing the input images. |
required |
probs
|
ndarray
|
Array of shape (N, K, H, W, D) containing the predicted class probabilities for each pixel. |
required |
sa
|
float
|
alpha standard deviation, the scale of the spatial part of the appearance/bilateral kernel. |
required |
sb
|
float
|
beta standard deviation, the scale of the color part of the appearance/bilateral kernel. |
required |
sg
|
float
|
gamma standard deviation, the scale of the smoothness/gaussian kernel. |
required |
w1
|
float
|
weight of the appearance/bilateral kernel. |
required |
w2
|
float
|
weight of the smoothness/gaussian kernel. |
required |
n_iter
|
int
|
Number of iterations for the CRF post-processing step. Defaults to 5. |
5
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of shape (N, K, H, W, D) containing the refined class probabilities for each pixel. |
Source code in napari_cellseg3d/code_models/crf.py
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 | |
crf_with_config
crf_with_config(image, prob, config: CRFConfig = None, log=logger.info)
Implements the CRF post-processing step for the WNet3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Array of shape (C, H, W, D) containing the input image. |
required |
prob
|
ndarray
|
Array of shape (K, H, W, D) containing the predicted class probabilities for each pixel. |
required |
config
|
CRFConfig
|
Configuration for the CRF post-processing step. Defaults to None. |
None
|
log
|
function
|
Logging function. Defaults to logger.info. |
info
|
Source code in napari_cellseg3d/code_models/crf.py
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 | |