Skip to content

Commit c83f021

Browse files
committed
Improve the performance of the sort function (2x).
Applies sorting directly on the sinogram along the second axis. There's no need to store and manipulate sorting indices, hence reducing memory overhead.
1 parent 0d1f8fc commit c83f021

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

httomolibgpu/prep/stripe.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,17 @@ def remove_stripe_based_sorting(
9393

9494

9595
def _rs_sort(sinogram, size, dim):
96-
"""
97-
Remove stripes using the sorting technique.
98-
"""
99-
sinogram = cp.transpose(sinogram)
100-
101-
#: Sort each column of the sinogram by its grayscale values
102-
#: Keep track of the sorting indices so we can reverse it below
103-
sortvals = cp.argsort(sinogram, axis=1)
104-
sortvals_reverse = cp.argsort(sortvals, axis=1)
105-
sino_sort = cp.take_along_axis(sinogram, sortvals, axis=1)
96+
"""remove stripes using the sorting technique."""
97+
sinogram = sinogram.T
10698

107-
#: Now apply the median filter on the sorted image along each row
108-
sino_sort = median_filter(sino_sort, (size, 1) if dim == 1 else (size, size))
99+
# Sort the sinogram directly based on pixel values
100+
sorted_sinogram = cp.sort(sinogram, axis=1) # Faster than argsort + take_along_axis
109101

110-
#: step 3: re-sort the smoothed image columns to the original rows
111-
sino_corrected = cp.take_along_axis(sino_sort, sortvals_reverse, axis=1)
102+
# Apply median filter (fully on GPU)
103+
window = (size, 1) if dim == 1 else (size, size)
104+
filtered_sinogram = median_filter(sorted_sinogram, size=window)
112105

113-
return cp.transpose(sino_corrected)
106+
return filtered_sinogram.T
114107

115108

116109
def remove_stripe_ti(

0 commit comments

Comments
 (0)