-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cristina/psdred
- Loading branch information
Showing
10 changed files
with
87 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
typing_extensions | ||
numpy>=1.20.0 | ||
scipy>=1.6.0 | ||
numpy>=1.25.0 | ||
scipy>=1.11.0 | ||
imageio>=2.17 | ||
tifffile | ||
matplotlib | ||
jaxlib>=0.4.13,<=0.4.37 | ||
jax>=0.4.13,<=0.4.37 | ||
jaxlib>=0.4.13,<=0.5.0 | ||
jax>=0.4.13,<=0.5.0 | ||
orbax-checkpoint>=0.5.0 | ||
flax>=0.8.0,<=0.10.2 | ||
pyabel>=0.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2024-2025 by SCICO Developers | ||
# All rights reserved. BSD 3-clause License. | ||
# This file is part of the SCICO package. Details of the copyright and | ||
# user license can be found in the 'LICENSE' file distributed with the | ||
# package. | ||
|
||
"""Utilities for CT data.""" | ||
|
||
from typing import Optional | ||
|
||
import jax.numpy as jnp | ||
from jax.scipy.ndimage import map_coordinates | ||
from jax.scipy.spatial.transform import Rotation | ||
from jax.typing import ArrayLike | ||
|
||
|
||
def rotate_volume( | ||
vol: ArrayLike, | ||
rot: Rotation, | ||
x: Optional[ArrayLike] = None, | ||
y: Optional[ArrayLike] = None, | ||
z: Optional[ArrayLike] = None, | ||
center: Optional[ArrayLike] = None, | ||
): | ||
"""Rotate a 3D array. | ||
Rotate a 3D array as specified by an instance of | ||
:class:`~jax.scipy.spatial.transform.Rotation`. Any axis coordinates | ||
that are not specified default to a range corresponding to the size | ||
of the array on that axis, starting at zero. | ||
Args: | ||
vol: Array to be rotated. | ||
rot: Rotation specification. | ||
x: Coordinates for :code:`x` axis (axis 0). | ||
y: Coordinates for :code:`y` axis (axis 1). | ||
z: Coordinates for :code:`z` axis (axis 2). | ||
center: A 3-vector specifying the center of rotation. | ||
Defaults to the center of the array. | ||
Returns: | ||
Rotated array. | ||
""" | ||
shape = vol.shape | ||
if x is None: | ||
x = jnp.arange(shape[0]) | ||
if y is None: | ||
y = jnp.arange(shape[1]) | ||
if z is None: | ||
z = jnp.arange(shape[2]) | ||
if center is None: | ||
center = (jnp.array(shape, dtype=jnp.float32) - 1.0) / 2.0 | ||
gx, gy, gz = jnp.meshgrid(x - center[0], y - center[1], z - center[2], indexing="ij") | ||
crd = jnp.stack((gx.ravel(), gy.ravel(), gz.ravel())) | ||
rot_crd = rot.as_matrix() @ crd + center[:, jnp.newaxis] # faster than rot.apply(crd.T) | ||
rot_vol = map_coordinates(vol, rot_crd.reshape((3,) + shape), order=1) | ||
return rot_vol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
|
||
from jax.scipy.spatial.transform import Rotation | ||
|
||
from scico.linop.xray import rotate_volume | ||
|
||
|
||
def test_rotate_volume(): | ||
vol = np.arange(27).reshape((3, 3, 3)) | ||
rot = Rotation.from_euler("XY", [90, 90], degrees=True) | ||
vol_rot = rotate_volume(vol, rot) | ||
np.testing.assert_allclose(vol.transpose((1, 2, 0)), vol_rot, rtol=1e-7) |