Shift
compute_shift(yxz_base, yxz_transform, min_score_2d, min_score_multiplier, min_score_min_dist, min_score_max_dist, neighb_dist_thresh, y_shifts, x_shifts, z_shifts=None, widen=None, max_range=None, z_scale=1, nz_collapse=None, z_step=3)
This finds the shift from those given that is best applied to yxz_base
to match yxz_transform
.
If the score
of this is below min_score_2d
, a widened search is performed.
If the score
is above min_score_2d
, a refined search is done about the best shift so as to find the absolute
best shift, not the best shift among those given.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yxz_base |
np.ndarray
|
|
required |
yxz_transform |
np.ndarray
|
|
required |
min_score_2d |
Optional[float]
|
If score of best shift is below this, will search among the widened shifts.
If |
required |
min_score_multiplier |
Optional[float]
|
Parameter used to find |
required |
min_score_min_dist |
Optional[float]
|
|
required |
min_score_max_dist |
Optional[float]
|
|
required |
neighb_dist_thresh |
float
|
Basically the distance below which neighbours are a good match.
Typical = |
required |
y_shifts |
np.ndarray
|
|
required |
x_shifts |
np.ndarray
|
|
required |
z_shifts |
Optional[np.ndarray]
|
|
None
|
widen |
Optional[List[int]]
|
|
None
|
max_range |
Optional[List[int]]
|
|
None
|
z_scale |
Union[float, List]
|
By what scale factor to multiply z coordinates to make them same units as xy.
I.e. |
1
|
nz_collapse |
Optional[int]
|
Maximum number of z-planes allowed to be flattened into a 2D slice.
If |
None
|
z_step |
int
|
|
3
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
float
|
|
float
|
|
dict
|
|
Source code in coppafish/stitch/shift.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
extend_array(array, extend_scale, direction='both')
Extrapolates array using its mean spacing in the direction specified by extend_sz
values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
np.ndarray
|
|
required |
extend_scale |
int
|
By how many values to extend the array. |
required |
direction |
str
|
One of the following, specifying how to extend the
|
'both'
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/stitch/shift.py
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 |
|
get_2d_slices(yxz_base, yxz_transform, nz_collapse)
This splits yxz_base
and yxz_transform
into n_slices = nz / nz_collapse
2D slices.
Then can do a 2D exhaustive search over multiple 2D slices instead of 3D exhaustive search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yxz_base |
np.ndarray
|
|
required |
yxz_transform |
np.ndarray
|
|
required |
nz_collapse |
Optional[int]
|
Maximum number of z-planes allowed to be flattened into a 2D slice.
If |
required |
Returns:
Type | Description |
---|---|
List[np.ndarray]
|
|
List[KDTree]
|
|
int
|
|
Source code in coppafish/stitch/shift.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
get_best_shift_2d(yx_base_slices, yx_transform_trees, neighb_dist_thresh, y_shifts, x_shifts, ignore_shifts=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yx_base_slices |
List[np.ndarray]
|
List of n_slices arrays indicating yx_base coordinates of spots in that slice. |
required |
yx_transform_trees |
List[KDTree]
|
List of n_slices KDTrees, each built from the yx_transform coordinates of spots in that slice. |
required |
neighb_dist_thresh |
float
|
Basically the distance below which neighbours are a good match.
Typical = |
required |
y_shifts |
np.ndarray
|
|
required |
x_shifts |
np.ndarray
|
|
required |
ignore_shifts |
Optional[np.ndarray]
|
|
None
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
float
|
|
np.ndarray
|
|
np.ndarray
|
|
Source code in coppafish/stitch/shift.py
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 |
|
get_best_shift_3d(yxz_base, yxz_transform_tree, neighb_dist_thresh, y_shifts, x_shifts, z_shifts, ignore_shifts=None)
Finds the shift from those given that is best applied to yx_base
to match yx_transform
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yxz_base |
np.ndarray
|
|
required |
yxz_transform_tree |
KDTree
|
KDTree built from coordinates of spots on transformed image
( |
required |
neighb_dist_thresh |
float
|
Basically the distance below which neighbours are a good match.
Typical = |
required |
y_shifts |
np.ndarray
|
|
required |
x_shifts |
np.ndarray
|
|
required |
z_shifts |
np.ndarray
|
|
required |
ignore_shifts |
Optional[np.ndarray]
|
|
None
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
float
|
|
np.ndarray
|
|
np.ndarray
|
|
Source code in coppafish/stitch/shift.py
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 |
|
get_score_thresh(all_shifts, all_scores, best_shift, min_dist, max_dist, thresh_multiplier)
Score thresh is the max of all scores from transforms between a distance=min_dist
and distance=max_dist
from the best_shift
.
I.e. we expect just for actual shift, there will be sharp gradient in score near it,
so threshold is multiple of nearby score.
If not the actual shift, then expect scores in this annulus will also be quite large.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_shifts |
np.ndarray
|
|
required |
all_scores |
np.ndarray
|
|
required |
best_shift |
Union[np.ndarray, List]
|
|
required |
min_dist |
float
|
|
required |
max_dist |
float
|
|
required |
thresh_multiplier |
float
|
|
required |
Returns:
Type | Description |
---|---|
float
|
score_thresh - Threshold used to determine if |
Optional[np.ndarray]
|
shift_thresh - |
Source code in coppafish/stitch/shift.py
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 252 253 254 255 256 257 258 259 260 261 |
|
refined_shifts(shifts, best_shift, refined_scale=0.5, extend_scale=2)
If shifts
is an array with mean spacing step
then this builds array
that covers from
best_shift - extend_scale * step
to best_shift + extend_scale * step
with a spacing of step*refined_scale
.
The new step, step*refined_scale
, is forced to be an integer.
If only one shift
provided, doesn't do anything.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shifts |
np.ndarray
|
|
required |
best_shift |
float
|
Value in |
required |
refined_scale |
float
|
Scaling to apply to find new shift spacing. |
0.5
|
extend_scale |
float
|
By how many steps to build new shifts. |
2
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
np.ndarray
|
|
Source code in coppafish/stitch/shift.py
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 |
|
shift_score(distances, thresh)
Computes a score to quantify how good a shift is based on the distances between the neighbours found. the value of this score is approximately the number of close neighbours found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distances |
np.ndarray
|
|
required |
thresh |
float
|
Basically the distance in pixels below which neighbours are a good match.
Typical = |
required |
Returns:
Type | Description |
---|---|
float
|
Score to quantify how good a shift is based on the distances between the neighbours found. |
Source code in coppafish/stitch/shift.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
update_shifts(search_shifts, prev_found_shifts)
Returns a new array of search_shifts
around the mean of prev_found_shifts
if new array has fewer entries or if
mean of prev_found_shifts
is outside initial range of search_shifts
.
If more than one prev_found_shifts
is outside the search_shifts
in the same way i.e. too high or too low,
search_shifts
will be updated too.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_shifts |
np.ndarray
|
|
required |
prev_found_shifts |
np.ndarray
|
|
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
|
np.ndarray
|
New set of shifts around mean of previously found shifts. |
np.ndarray
|
Will only return updated shifts if new array has fewer entries than before or mean of |
np.ndarray
|
is outside range of |
Source code in coppafish/stitch/shift.py
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 |
|