Skip to content

Commit 8039887

Browse files
jhlegarretaoesteban
andcommitted
REF: Remove image change percentage function
Remove image change percentage function from the `analysis.utils` module as it is a metric of image similarity rather than a metric of motion. Co-authored-by: Oscar Esteban <code@oscaresteban.es>
1 parent d8b8c2a commit 8039887

File tree

2 files changed

+0
-62
lines changed

2 files changed

+0
-62
lines changed

nitransforms/analysis/utils.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,6 @@ def compute_fd_from_transform(
9595
return np.mean(np.linalg.norm(test_xfm.map(fd_coords) - fd_coords, axis=-1))
9696

9797

98-
def compute_percentage_change(
99-
reference: np.ndarray,
100-
test: np.ndarray,
101-
mask: np.ndarray,
102-
) -> np.ndarray:
103-
"""Compute motion change between reference and test as a percentage.
104-
105-
If a mask is provided, the computation is only provided within the mask.
106-
Also, null values are ignored.
107-
108-
Parameters
109-
----------
110-
reference : :obj:`~numpy.ndarray`
111-
Reference imaging volume.
112-
test : :obj:`~numpy.ndarray`
113-
Test (shifted) imaging volume.
114-
mask : :obj:`~numpy.ndarray`
115-
Mask for value consideration.
116-
117-
Returns
118-
-------
119-
rel_diff : :obj:`~numpy.ndarray`
120-
Motion change between reference and test.
121-
"""
122-
123-
# Avoid divide-by-zero errors
124-
eps = 1e-5
125-
rel_diff = np.zeros_like(reference)
126-
mask = mask.copy()
127-
mask[reference <= eps] = False
128-
rel_diff[mask] = 100 * (test[mask] - reference[mask]) / reference[mask]
129-
130-
return rel_diff
13198

13299

133100
def displacements_within_mask(

nitransforms/tests/test_analysis.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from nitransforms.analysis.utils import (
1111
compute_fd_from_motion,
1212
compute_fd_from_transform,
13-
compute_percentage_change,
1413
displacements_within_mask,
1514
extract_motion_parameters,
1615
identify_spikes,
@@ -133,34 +132,6 @@ def test_extract_motion_parameters(affine, expected_trans, expected_rot):
133132
assert np.allclose(params[3:], expected_rot)
134133

135134

136-
@pytest.mark.parametrize(
137-
"reference, test, mask, expected",
138-
[
139-
(
140-
np.array([[1.0, 2.0], [0.0, 4.0]]),
141-
np.array([[2.0, 1.0], [3.0, 8.0]]),
142-
np.array([[True, True], [True, True]]),
143-
np.array([[(2.0 - 1.0) / 1.0, (1.0 - 2.0) / 2.0], [0, (8.0 - 4.0) / 4.0]]) * 100,
144-
),
145-
(
146-
np.zeros((2,2)),
147-
np.ones((2,2)),
148-
np.ones((2,2), dtype=bool),
149-
np.zeros((2,2)),
150-
),
151-
(
152-
np.array([[5, 10], [15, 20]]),
153-
np.array([[10, 5], [30, 10]]),
154-
np.array([[False, True], [True, False]]),
155-
np.array([[0, (5-10)/10], [(30-15)/15, 0]]) * 100,
156-
),
157-
],
158-
)
159-
def test_compute_percentage_change_param(reference, test, mask, expected):
160-
result = compute_percentage_change(reference, test, mask)
161-
np.testing.assert_array_almost_equal(result, expected)
162-
163-
164135
def test_identify_spikes(request):
165136
rng = request.node.rng
166137

0 commit comments

Comments
 (0)