spline-resize
Resize (currently only 3D, maybe later 2D) PyTorch tensors via B-spline interpolation
B-spline results in higher quality than 'trilinear'(=best PyTorch-native 3D method)
Currently, spline-resize only supports zero padding!
🛠️ Install via: pip install spline-resize
Usage 💡
To resize a 3D image(=5D tensor, due to batch and channel dim.) use resize
import torch
import spline_resize as sr
x = torch.linspace(0, 1, 5**3).view(1, 1, 5, 5, 5)
x_large = sr.resize(x, size=(7, 7, 7))
The arguments size, scale_factor & align_corners are explained here
To resample a 3D image with a grid of coordinates use grid_sample
import torch.nn.functional as F
# affine matrix that rotates image
affine = torch.tensor([[[1, .1, 0, 0],
[.1, 1, 0, 0],
[0, 0, 1, 0]]])
grid = F.affine_grid(affine, size=(1, 3, 7, 7, 7))
x = torch.linspace(0, 1, 5**3).view(1, 1, 5, 5, 5)
x_large_rotated = sr.grid_sample(x, grid)
Both resize and grid_sample also take the function arguments
prefilter: Applies prefilter usually used prior to sampling. Default:Truemask_value: Exclude value (e.g. 0) from prefilter. Default:None
Release files for spline-resize 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spline_resize-0.1.1.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spline_resize-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / spline_resize-0.1.1.tar.gz
| Download URL | spline_resize-0.1.1.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e57840519ee56c71724f1d2caea58481acbe5bfbf6ebc90ab22cfcb6e51b1d6d
|
|
BLAKE2b-256 checksum How to use checksums |
2d42984de52a113eff87201b34e6cdb9749e1f4279300506e3f81290ba6af229
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic
|
Release files / spline_resize-0.1.1-py3-none-any.whl
| Download URL | spline_resize-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fc571ff7fe0fad4aaf46e725fb65ee3088db37f9512a4049173c303571f9ae7
|
|
BLAKE2b-256 checksum How to use checksums |
a4a7edf38d0b7610176acb70e7e81655a74b67da1e849a7088dd010d69409f3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic
|