Skip to content

Commit

Permalink
Small compatibility fixes. (#1633)
Browse files Browse the repository at this point in the history
* Compatibility with scikit-image>=0.17.

* Compatibility with numpy>=1.24.

Older versions would automatically convert the meshgrid used for scikit-image Radon transform
to a ragged array, i.e. array of arrays. Newer versions do not do this anymore and need to
be explicitly asked for it.
  • Loading branch information
leftaroundabout authored Feb 13, 2024
1 parent d4a5ed6 commit c2c56d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions odl/discr/discr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ def __call__(self, x, out=None):
Parameters
----------
x : `meshgrid` or `numpy.ndarray`
Evaluation points of the interpolator
x : `meshgrid` (i.e., tuple of arrays) if `input_type` is meshgrid,
else `numpy.ndarray`.
Evaluation points of the interpolator.
out : `numpy.ndarray`, optional
Array to which the results are written. Needs to have
correct shape according to input ``x``.
Expand All @@ -565,7 +566,12 @@ def __call__(self, x, out=None):
Interpolated values. If ``out`` was given, the returned
object is a reference to it.
"""
x = np.asarray(x)
if self.input_type == 'meshgrid':
# Given a meshgrid, the evaluation will be on a ragged array.
x = np.asarray(x, dtype=object)
else:
x = np.asarray(x)

ndim = len(self.coord_vecs)
scalar_out = False

Expand Down
8 changes: 7 additions & 1 deletion odl/tomo/backends/skimage_radon.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ def skimage_radon_back_projector(sinogram, geometry, vol_space, out=None):
# Only do asserts here since these are backend functions
assert out in vol_space

# scikit-image changed the name of this parameter in version 0.17
if (skimage.__version__ < '0.17'):
filter_disable = {"filter": None}
else:
filter_disable = {"filter_name": None}

# Rotate back from (rows, cols) to (x, y), then back-project (no filter)
backproj = iradon(
skimage_sinogram.asarray().T,
theta,
output_size=vol_space.shape[0],
filter=None,
circle=False,
**filter_disable
)
out[:] = np.rot90(backproj, -1)

Expand Down

0 comments on commit c2c56d7

Please sign in to comment.