Skip to main content

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: True
  • mask_value: Exclude value (e.g. 0) from prefilter. Default: None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spline_resize-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spline_resize-0.1.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

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

Hashes for spline_resize-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e57840519ee56c71724f1d2caea58481acbe5bfbf6ebc90ab22cfcb6e51b1d6d
MD5 d50b2ba92acb7112b350e3cf48cea7d8
BLAKE2b-256 2d42984de52a113eff87201b34e6cdb9749e1f4279300506e3f81290ba6af229

See more details on using hashes here.

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

Hashes for spline_resize-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fc571ff7fe0fad4aaf46e725fb65ee3088db37f9512a4049173c303571f9ae7
MD5 8f9bc9234a58b064b1a8a7eff16bdf32
BLAKE2b-256 a4a7edf38d0b7610176acb70e7e81655a74b67da1e849a7088dd010d69409f3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page