This release is a pre-release and may not be stable for production use.
torch-image-interpolation
1D/2D/3D image interpolation routines in PyTorch.
Why?
This package provides a simple, consistent API for
- sampling values from 1D/2D/3D images (
sample_image_1d()/sample_image_2d()/sample_image_3d()) - inserting values into 2D/3D images (
insert_into_image_1d()/insert_into_image_2d()/insert_into_image_3d())
Operations are differentiable, multichannel data and complex valued images are supported.
torch.nn.functional.grid_sample
is used under the hood for sampling.
Installation
pip install torch-image-interpolation
Usage
Coordinate System
This library uses an array-like coordinate system where coordinate values span from 0
to dim_size - 1 for each dimension.
Fractional coordinates are supported and values are interpolated appropriately.
1D Images
For 1D images (vectors) with shape (w, ) or (c, w)
coordinates are a (...) array of coordinates in the w dimension.
For example, in a (28, ) image, valid coordinates range from 0 to 27.
2D Images
For 2D images with shape (h, w) or (c, h, w):
Coordinates are ordered as [y, x] where:
yis the position in the height dimension (first dimension of shape)xis the position in the width dimension (second dimension of shape)
For example, in a (28, 28) image, valid coordinates range from [0, 0] to [27, 27]
3D Images
For 3D images with shape (d, h, w) or (c, d, h, w):
Coordinates are ordered as [z, y, x] where:
zis the position in the depth dimension (first dimension of shape)yis the position in the height dimension (second dimension of shape)xis the position in the width dimension (third dimension of shape)
For example, in a (28, 28, 28) volume, valid coordinates range from [0, 0, 0] to
[27, 27, 27].
Sample from image
import torch
import numpy as np
from torch_image_interpolation import sample_image_2d
# example (h, w) image
image = torch.rand((28, 28))
# make an arbitrary stack (..., 2) of 2d coords
coords = torch.tensor(np.random.uniform(low=0, high=27, size=(6, 7, 8, 2))).float()
# sampling returns a (6, 7, 8) array of samples
# using bilinear interpolation (the default)
sample_bilinear = sample_image_2d(image=image, coordinates=coords, interpolation='bilinear')
# or a different interpolation mode...
samples_nearest = sample_image_2d(image=image, coordinates=coords, interpolation='nearest')
samples_bicubic = sample_image_2d(image=image, coordinates=coords, interpolation='bicubic')
The API is identical for 1D (w) or 3D (d, h, w) images but takes (...) or (..., 3) arrays of
coordinates respectively.
Sampling is supported for multichannel images in 1D (c, w), 2D (c, h, w) and 3D (c, d, h, w).
Sampling multichannel images returns (..., c) arrays of values.
Insert into image
import torch
import numpy as np
from torch_image_interpolation import insert_into_image_2d
# example (h, w) image
image = torch.zeros((28, 28))
# make an arbitrary stack (..., 2) of 2d coords
coords = torch.tensor(np.random.uniform(low=0, high=27, size=(3, 4, 2)))
# generate random values to place at coords
values = torch.rand(size=(3, 4))
# insert values into the image with bilinear interpolation (the default)
image_bilinear, weights_bilinear = insert_into_image_2d(
values, image=image, coordinates=coords, interpolation='bilinear'
)
# you can specify a different interpolation mode
image_nearest, weights_nearest = insert_into_image_2d(
values, image=image, coordinates=coords, interpolation='nearest'
)
The API is identical for 1D (w, ) and 3D (d, h, w) images but requires (...) and (..., 3)` arrays of
coordinates respectively.
Insertion is supported for multichannel images in 1D (c, w), 2D (c, h, w) and 3D (c, d, h, w).
Inserting into multichannel images requires (..., c) arrays of values.
Similar packages
Metadata
Release files for torch-image-interpolation 0.6.0rc2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torch_image_interpolation-0.6.0rc2.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torch_image_interpolation-0.6.0rc2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.8 kB
Release files / torch_image_interpolation-0.6.0rc2.tar.gz
| Download URL | torch_image_interpolation-0.6.0rc2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92219a5202c6d9fade4553549d3134b0d249151eb0bd75adb24e58daa4a70668
|
|
BLAKE2b-256 checksum How to use checksums |
21f0f04b676958c90453ebd345d2cce89e645ded6f0553622ec207161e19b66a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logRelease files / torch_image_interpolation-0.6.0rc2-py3-none-any.whl
| Download URL | torch_image_interpolation-0.6.0rc2-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
093fb5e67f93e04a679b8ecae260251581fb9f09d409430fb6e4e0cc5ce7cf34
|
|
BLAKE2b-256 checksum How to use checksums |
35cfd5dd2237de1e5d137af71ef141c57c236f6988aeabb60bddce620f0d3e2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency log