B-spline interpolation in PyTorch
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spline_resize-0.1.1.tar.gz.
File metadata
- Download URL: spline_resize-0.1.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e57840519ee56c71724f1d2caea58481acbe5bfbf6ebc90ab22cfcb6e51b1d6d
|
|
| MD5 |
d50b2ba92acb7112b350e3cf48cea7d8
|
|
| BLAKE2b-256 |
2d42984de52a113eff87201b34e6cdb9749e1f4279300506e3f81290ba6af229
|
File details
Details for the file spline_resize-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spline_resize-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc571ff7fe0fad4aaf46e725fb65ee3088db37f9512a4049173c303571f9ae7
|
|
| MD5 |
8f9bc9234a58b064b1a8a7eff16bdf32
|
|
| BLAKE2b-256 |
a4a7edf38d0b7610176acb70e7e81655a74b67da1e849a7088dd010d69409f3f
|