transforms
navis.transforms.AffineTransform
#
Affine transformation of 3D spatial data.
PARAMETER | DESCRIPTION |
---|---|
matrix |
TYPE: |
Examples:
A simple scaling transform
>>> from navis import transforms
>>> import numpy as np
>>> M = np.diag([1e3, 1e3, 1e3, 1])
>>> tr = transforms.affine.AffineTransform(M)
>>> points = np.array([[0, 0, 0], [1, 1, 1]])
>>> tr.xform(points)
array([[ 0., 0., 0.],
[1000., 1000., 1000.]])
Source code in navis/transforms/affine.py
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
__init__
#
Initialize transform.
Source code in navis/transforms/affine.py
44 45 46 47 48 49 50 51 |
|
copy
#
Return copy of transform.
Source code in navis/transforms/affine.py
69 70 71 72 73 74 75 76 77 78 |
|
xform
#
Apply transform to points.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
invert |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | The transformed points. |
Source code in navis/transforms/affine.py
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 |
|
navis.transforms.AliasTransform
#
Helper transform that simply passes points through.
Useful for defining aliases.
Source code in navis/transforms/base.py
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 |
|
__init__
#
Initialize.
Source code in navis/transforms/base.py
79 80 81 |
|
copy
#
Return copy.
Source code in navis/transforms/base.py
93 94 95 96 97 |
|
xform
#
Pass through.
Note that the returned points are NOT a copy but the originals.
Source code in navis/transforms/base.py
99 100 101 102 103 104 |
|
navis.transforms.CMTKtransform
#
CMTK transforms of 3D spatial data.
Requires CMTK to be installed.
PARAMETER | DESCRIPTION |
---|---|
regs |
TYPE: |
directions |
TYPE: |
threads |
TYPE: |
Examples:
>>> from navis import transforms
>>> tr = transforms.cmtk.CMTKtransform('/path/to/CMTK_directory.list')
>>> tr.xform(points)
Source code in navis/transforms/cmtk.py
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 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 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 262 263 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 316 317 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 |
|
regargs: list
property
#
Generate regargs.
append
#
Add another transform.
PARAMETER | DESCRIPTION |
---|---|
transform |
TYPE: |
direction |
TYPE: |
Source code in navis/transforms/cmtk.py
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 |
|
check_if_possible
#
Check if this transform is possible.
Source code in navis/transforms/cmtk.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
copy
#
Return copy.
Source code in navis/transforms/cmtk.py
315 316 317 318 319 320 321 322 323 324 |
|
from_file
staticmethod
#
Generate CMTKtransform from file.
PARAMETER | DESCRIPTION |
---|---|
filepath |
TYPE: |
**kwargs |
DEFAULT: |
RETURNS | DESCRIPTION |
---|---|
CMTKtransform | |
Source code in navis/transforms/cmtk.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
make_args
#
Generate arguments passed to subprocess.
Source code in navis/transforms/cmtk.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
parse_cmtk_output
#
Parse CMTK output.
Briefly, CMTK output will be a byte literal like this:
b'311 63 23 \n275 54 25 \n'
In case of failed transforms we will get something like this where the original coordinates are returned with a "FAILED" flag
b'343 72 23 \n-10 -10 -10 FAILED \n'
Parameter
output : tuple of (b'', None) Stdout of CMTK call. fail_value Value to use for points that failed to transform. By default we use np.nan
.
RETURNS | DESCRIPTION |
---|---|
pointsxf | The parse transformed points. TYPE: |
Source code in navis/transforms/cmtk.py
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 |
|
xform
#
Xform data.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
affine_only |
TYPE: |
affine_fallback |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | Transformed points. Points that failed to transform will be TYPE: |
Source code in navis/transforms/cmtk.py
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 |
|
xform_image
#
Transform an image using CMTK's reformatx.
Parameters
im : 3D numpy array | filepath The floating image to transform. target : str | TemplateBrain | (Nx, Ny, Nz, dx, dy, dz) | (Nx, Ny, Nz, dx, dy, dz, Ox, Oy, Oz) Defines the target image: dimensions in voxels (N), the voxel size (d) and optionally an origin (0) for the target image. Can be provided as a string (name of a template), a TemplateBrain object, a tuple/list/array with the target specs. out : str, optional The filepath to save the transformed image. If None (default), will return the transformed image as np.ndarray. interpolation : "linear" | "nn" | "cubic" | "pv" | "sinc-cosine" | "sinc-hamming" The interpolation method to use. verbose : bool Whether to print CMTK output.
RETURNS | DESCRIPTION |
---|---|
np.ndarray | None | If out is None, returns the transformed image as np.ndarray. Otherwise, None. |
Source code in navis/transforms/cmtk.py
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 |
|
navis.transforms.ElastixTransform
#
Elastix transforms of 3D spatial data.
Requires Elastix. Based on code by Jasper Phelps (https://github.com/jasper-tms/pytransformix).
Note that elastix transforms can not be inverted!
PARAMETER | DESCRIPTION |
---|---|
file |
TYPE: |
copy_files |
TYPE: |
Examples:
>>> from navis import transforms
>>> tr = transforms.ElastixTransform('/path/to/transform/transform')
>>> tr.xform(points)
Source code in navis/transforms/elastix.py
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 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 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 262 263 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 |
|
check_if_possible
#
Check if this transform is possible.
Source code in navis/transforms/elastix.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
copy
#
Return copy.
Source code in navis/transforms/elastix.py
181 182 183 184 185 186 187 188 189 190 191 192 |
|
read_output_file
#
Load output file.
Parameter
filepath : str Filepath to output file.
RETURNS | DESCRIPTION |
---|---|
pointsxf | The parse transformed points. TYPE: |
Source code in navis/transforms/elastix.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
write_input_file
#
Write a numpy array in format required by transformix.
Source code in navis/transforms/elastix.py
194 195 196 197 198 199 |
|
xform
#
Xform data.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
return_logs |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | Transformed points. TYPE: |
Source code in navis/transforms/elastix.py
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 252 253 254 255 256 257 258 259 260 261 262 263 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 |
|
navis.transforms.FunctionTransform
#
Apply custom function as transform.
PARAMETER | DESCRIPTION |
---|---|
func |
TYPE: |
Source code in navis/transforms/base.py
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 |
|
__init__
#
Initialize.
Source code in navis/transforms/base.py
117 118 119 120 121 |
|
copy
#
Return copy.
Source code in navis/transforms/base.py
131 132 133 134 135 |
|
xform
#
Xform data.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | Transformed points. TYPE: |
Source code in navis/transforms/base.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
navis.transforms.H5transform
#
Hdf5 transform of 3D spatial data.
See here for specifications of the format.
PARAMETER | DESCRIPTION |
---|---|
f |
TYPE: |
direction |
TYPE: |
level |
TYPE: |
cache |
TYPE: |
full_ingest |
TYPE: |
Source code in navis/transforms/h5reg.py
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 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 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 262 263 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 316 317 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 |
|
use_cache
property
writable
#
Whether to cache the deformation field.
__init__
#
Init class.
Source code in navis/transforms/h5reg.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 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 |
|
copy
#
Return copy.
Source code in navis/transforms/h5reg.py
189 190 191 192 193 194 195 |
|
from_file
staticmethod
#
Generate H5transform from file.
PARAMETER | DESCRIPTION |
---|---|
filepath |
TYPE: |
**kwargs |
DEFAULT: |
RETURNS | DESCRIPTION |
---|---|
H5transform | |
Source code in navis/transforms/h5reg.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
full_ingest
#
Fully ingest the deformation field.
Source code in navis/transforms/h5reg.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
precache
#
Cache deformation field for given bounding box.
PARAMETER | DESCRIPTION |
---|---|
bbox |
TYPE: |
padding |
TYPE: |
Source code in navis/transforms/h5reg.py
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 252 253 254 255 256 257 258 259 260 261 262 |
|
xform
#
Xform data.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
affine_fallback |
TYPE: |
force_deform |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | Transformed points. Points outside the deformation field will have only the affine part of the transform applied. TYPE: |
Source code in navis/transforms/h5reg.py
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 316 317 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 |
|
navis.transforms.TPStransform
#
Thin Plate Spline transforms of 3D spatial data.
PARAMETER | DESCRIPTION |
---|---|
landmarks_source |
TYPE: |
landmarks_target |
TYPE: |
Examples:
>>> from navis import transforms
>>> import numpy as np
>>> # Generate some mock landmarks
>>> src = np.array([[0, 0, 0], [10, 10, 10], [100, 100, 100], [80, 10, 30]])
>>> trg = np.array([[1, 15, 5], [9, 18, 21], [80, 99, 120], [5, 10, 80]])
>>> tr = transforms.thinplate.TPStransform(src, trg)
>>> points = np.array([[0, 0, 0], [50, 50, 50]])
>>> tr.xform(points)
array([[ 1. , 15. , 5. ],
[40.55555556, 54. , 65. ]])
Source code in navis/transforms/thinplate.py
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 |
|
__init__
#
Initialize class.
Source code in navis/transforms/thinplate.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
copy
#
Make copy.
Source code in navis/transforms/thinplate.py
113 114 115 116 117 118 119 |
|
xform
#
Transform points.
PARAMETER | DESCRIPTION |
---|---|
points |
TYPE: |
RETURNS | DESCRIPTION |
---|---|
pointsxf | Transformed points. TYPE: |
Source code in navis/transforms/thinplate.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|