Skip to main content

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: True
  • mask_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)

Source distribution for spline-resize 0.1.1
File Size Uploaded
spline_resize-0.1.1.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spline-resize 0.1.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page