Linear interpolation and gridding for 2D and 3D images in PyTorch
Project description
torch-image-lerp
Linear 2D/3D image interpolation and gridding in PyTorch.
Why?
This package provides a simple, consistent API for
- sampling from 2D/3D images (
sample_image_2d()
/sample_image_3d()
) - inserting values into 2D/3D images (
insert_into_image_2d()
,insert_into_image_3d
)
Operations are differentiable.
Installation
pip install torch-image-lerp
Usage
Sample from image
import torch
import numpy as np
from torch_image_lerp import sample_image_2d
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)))
# sampling returns a (6, 7, 8) array of samples obtained by linear interpolation
samples = sample_image_2d(image=image, coordinates=coords)
The API is identical for 3D but takes (..., 3)
coordinates and a (d, h, w)
image.
Insert into image
import torch
import numpy as np
from torch_image_lerp import insert_into_image_2d
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))
# sampling returns a (6, 7, 8) array of samples obtained by linear interpolation
samples = insert_into_image_2d(values, image=image, coordinates=coords)
The API is identical for 3D but takes (..., 3)
coordinates and a (d, h, w)
image.
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
torch_image_lerp-0.0.2.tar.gz
(9.8 kB
view hashes)
Built Distribution
Close
Hashes for torch_image_lerp-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b17283d76cedeb2a2da955cd59ae48a52df64686d34b6b17579d384c25eb4d |
|
MD5 | d842d6038e56d4014dd0fddd5eba5467 |
|
BLAKE2b-256 | 9ccfe9677233d36fc03847567e3c71299f53aae575f99e7881424621b42804dd |