|
24 | 24 | from httomolibgpu import cupywrapper |
25 | 25 |
|
26 | 26 | cp = cupywrapper.cp |
27 | | - |
28 | 27 | nvtx = cupywrapper.nvtx |
29 | 28 |
|
| 29 | +from httomolibgpu.cuda_kernels import load_cuda_module |
| 30 | +from cupyx.scipy.ndimage import shift, gaussian_filter |
| 31 | +from skimage.registration import phase_cross_correlation |
| 32 | +from cupyx.scipy.fftpack import get_fft_plan |
| 33 | +from cupyx.scipy.fft import rfft2 |
| 34 | + |
30 | 35 | import math |
31 | 36 | from typing import List, Literal, Optional, Tuple, Union |
32 | 37 |
|
@@ -96,8 +101,7 @@ def __find_center_vo( |
96 | 101 | step: float = 0.25, |
97 | 102 | ratio: float = 0.5, |
98 | 103 | drop: int = 20, |
99 | | -) -> float: |
100 | | - from cupyx.scipy.ndimage import gaussian_filter |
| 104 | +) -> float: |
101 | 105 |
|
102 | 106 | if data.ndim == 2: |
103 | 107 | data = cp.expand_dims(data, 1) |
@@ -185,7 +189,6 @@ def _search_fine(sino, srad, step, init_cen, ratio, drop): |
185 | 189 |
|
186 | 190 | @nvtx.annotate() |
187 | 191 | def _create_mask(nrow, ncol, radius, drop): |
188 | | - from httomolibgpu.cuda_kernels import load_cuda_module |
189 | 192 |
|
190 | 193 | du = 1.0 / ncol |
191 | 194 | dv = (nrow - 1.0) / (nrow * 2.0 * np.pi) |
@@ -258,11 +261,6 @@ def _calculate_chunks( |
258 | 261 |
|
259 | 262 | @nvtx.annotate() |
260 | 263 | def _calculate_metric(list_shift, sino1, sino2, sino3, mask, out): |
261 | | - from httomolibgpu.cuda_kernels import load_cuda_module |
262 | | - from cupyx.scipy.ndimage import shift |
263 | | - from cupyx.scipy.fftpack import get_fft_plan |
264 | | - from cupyx.scipy.fft import rfft2 |
265 | | - |
266 | 264 | # this tries to simplify - if shift_col is integer, no need to spline interpolate |
267 | 265 | assert list_shift.dtype == cp.float32, "shifts must be single precision floats" |
268 | 266 | assert sino1.dtype == cp.float32, "sino1 must be float32" |
@@ -351,8 +349,6 @@ def _calculate_metric(list_shift, sino1, sino2, sino3, mask, out): |
351 | 349 |
|
352 | 350 | @nvtx.annotate() |
353 | 351 | def _downsample(sino, level, axis): |
354 | | - from httomolibgpu.cuda_kernels import load_cuda_module |
355 | | - |
356 | 352 | assert sino.dtype == cp.float32, "single precision floating point input required" |
357 | 353 | assert sino.flags["C_CONTIGUOUS"], "list_shift must be C-contiguous" |
358 | 354 |
|
@@ -612,7 +608,6 @@ def _search_overlap( |
612 | 608 | Initial position of the searching window where the position |
613 | 609 | corresponds to the center of the window. |
614 | 610 | """ |
615 | | - from cupyx.scipy.ndimage import gaussian_filter |
616 | 611 |
|
617 | 612 | if denoise is True: |
618 | 613 | # note: the filtering makes the output contiguous |
@@ -650,8 +645,6 @@ def _calc_metrics(mat1, mat2, win_width, side, use_overlap, norm): |
650 | 645 | assert mat1.flags.c_contiguous, "only contiguos arrays supported" |
651 | 646 | assert mat2.flags.c_contiguous, "only contiguos arrays supported" |
652 | 647 |
|
653 | | - from httomolibgpu.cuda_kernels import load_cuda_module |
654 | | - |
655 | 648 | _calc_metrics_module = load_cuda_module( |
656 | 649 | "calc_metrics", |
657 | 650 | name_expressions=[ |
@@ -766,9 +759,7 @@ def __find_center_pc( |
766 | 759 | tol: float = 0.5, |
767 | 760 | rotc_guess: Union[float, Optional[str]] = None, |
768 | 761 | ) -> float: |
769 | | - from cupyx.scipy.ndimage import shift |
770 | | - from skimage.registration import phase_cross_correlation |
771 | | - |
| 762 | + |
772 | 763 | imgshift = 0.0 if rotc_guess is None else rotc_guess - (proj1.shape[1] - 1.0) / 2.0 |
773 | 764 |
|
774 | 765 | proj1 = shift(proj1, [0, -imgshift], mode="constant", cval=0) |
|
0 commit comments