Skip to content

Commit

Permalink
fix error in 3D sampling leading to test failure (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisterburt authored Jul 5, 2024
1 parent ff1b114 commit 67bb126
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/torch_image_lerp/linear_interpolation_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def sample_image_3d(
`(..., )` array of samples from `image`.
"""
complex_input = torch.is_complex(image)

# setup for sampling with torch.nn.functional.grid_sample
coordinates, ps = einops.pack([coordinates], pattern='* zyx')
n_samples = coordinates.shape[0]
Expand All @@ -52,11 +53,12 @@ def sample_image_3d(
padding_mode='border', # this increases sampling fidelity at edges
align_corners=True,
)

if complex_input is True:
samples = einops.rearrange(samples, 'b complex 1 1 1 -> b complex')
samples = torch.view_as_complex(samples.contiguous()) # (b, )
else:
samples = einops.rearrange(samples, 'b c 1 1 1 -> b c')
samples = einops.rearrange(samples, 'b 1 1 1 1 -> b')

# set samples from outside of volume to zero
coordinates = einops.rearrange(coordinates, 'b 1 1 1 zyx -> b zyx')
Expand Down

0 comments on commit 67bb126

Please sign in to comment.