Skip to content

Commit 29aff33

Browse files
committed
few corrections and small data tests to pass
1 parent 0338011 commit 29aff33

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

httomolibgpu/recon/rotation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from cupyx.scipy.ndimage import shift, gaussian_filter
3434
from skimage.registration import phase_cross_correlation
3535
from cupyx.scipy.fftpack import get_fft_plan
36-
from cupyx.scipy.fft import fft, rfft2, fft2, fftshift
36+
from cupyx.scipy.fft import rfft2, fft2, fftshift
3737
else:
3838
load_cuda_module = Mock()
3939
shift = Mock()
@@ -58,7 +58,7 @@
5858
def find_center_vo(
5959
data: cp.ndarray,
6060
ind: Optional[int] = None,
61-
average_radius: int = 5,
61+
average_radius: Optional[int] = 0,
6262
cor_initialisation_value: Optional[float] = None,
6363
smin: int = -100,
6464
smax: int = 100,
@@ -68,7 +68,7 @@ def find_center_vo(
6868
drop: int = 20,
6969
) -> float:
7070
"""
71-
Find rotation axis location (aka centre of rotation) using Nghia Vo's method. See the paper
71+
Find the rotation axis location (aka the centre of rotation) using Nghia Vo's method. See the paper
7272
:cite:`vo2014reliable`.
7373
7474
Parameters
@@ -78,7 +78,7 @@ def find_center_vo(
7878
ind : int, optional
7979
Index of the slice to be used to estimate the CoR. If None is given, then the central sinogram will be extracted from the data array with a possible averaging, see .
8080
average_radius : int, optional
81-
Averaging multiple sinograms around the sinogram defined by ind parameter to improve the signal-to-noise ratio. It is sensible to have this parameter to be less than 10.
81+
Averaging multiple sinograms around the ind-indexed sinogram to improve the signal-to-noise ratio. It is recommended to keep this parameter smaller than 10.
8282
cor_initialisation_value : float, optional
8383
The initial approximation for the centre of rotation. If the value is None, use the horizontal centre of the projection/sinogram image.
8484
smin : int, optional
@@ -162,7 +162,11 @@ def find_center_vo(
162162
fine_cen = _search_fine(
163163
_sino_fs, fine_srange, step, float(init_cen) * dsp_detX + off_set, ratio, drop
164164
)
165-
return cp.asnumpy(fine_cen)
165+
cen_np = np.float32(cp.asnumpy(fine_cen))
166+
if cen_np == 0.0:
167+
return cor_initialisation_value
168+
else:
169+
return cen_np
166170

167171

168172
def _search_coarse(sino, smin, smax, ratio, drop):

tests/test_recon/test_rotation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ def test_find_center_vo(data, flats, darks):
2222
data = normalize(data, flats, darks)
2323

2424
# --- testing the center of rotation on tomo_standard ---#
25-
cor = find_center_vo(data)
25+
cor = find_center_vo(
26+
data.copy(),
27+
average_radius=0,
28+
)
2629

2730
data = None #: free up GPU memory
2831
assert_allclose(cor, 79.5)
2932

30-
#: Check that we only get a float32 output
31-
assert cor.dtype == np.float32
32-
3333

3434
def test_find_center_vo_ones(ensure_clean_memory):
3535
mat = cp.ones(shape=(103, 450, 230), dtype=cp.float32)
3636
cor = find_center_vo(mat)
3737

38-
assert_allclose(cor, 59.0)
38+
assert_allclose(cor, 8)
3939
mat = None #: free up GPU memory
4040

4141

@@ -44,7 +44,7 @@ def test_find_center_vo_random(ensure_clean_memory):
4444
data_host = np.random.random_sample(size=(900, 1, 1280)).astype(np.float32) * 2.0
4545
data = cp.asarray(data_host, dtype=np.float32)
4646
cent = find_center_vo(data)
47-
assert_allclose(cent, 680.75)
47+
assert_allclose(cent, 550.25)
4848

4949

5050
def test_find_center_vo_big_data(sino3600):

0 commit comments

Comments
 (0)