Skip to content

Commit 5fab84c

Browse files
committed
Avoid making an extra copy
1 parent f86b4f5 commit 5fab84c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

httomolibgpu/prep/stripe.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ def _rs_large(sinogram, snr, size, matindex, drop_ratio=0.1, norm=True):
320320

321321

322322
def _rs_dead(sinogram, snr, size, matindex, norm=True):
323-
"""
324-
Remove unresponsive and fluctuating stripes.
325-
"""
323+
"""remove unresponsive and fluctuating stripes"""
326324
sinogram = cp.copy(sinogram) # Make it mutable
327325
(nrow, _) = sinogram.shape
328326
sinosmooth = uniform_filter1d(sinogram, 10, axis=0)
@@ -333,22 +331,23 @@ def _rs_dead(sinogram, snr, size, matindex, norm=True):
333331
listfact = listdiff / listdiffbck
334332

335333
listmask = _detect_stripe(listfact, snr)
334+
del listfact
336335
listmask = binary_dilation(listmask, iterations=1).astype(listmask.dtype)
337336
listmask[0:2] = 0.0
338337
listmask[-2:] = 0.0
339-
listx = cp.where(listmask < 1.0)[0]
340-
listy = cp.arange(nrow)
341-
matz = sinogram[:, listx]
342338

339+
listx = cp.where(listmask < 1.0)[0]
343340
listxmiss = cp.where(listmask > 0.0)[0]
341+
del listmask
344342

345-
# finter = interpolate.interp2d(listx.get(), listy.get(), matz.get(), kind='linear')
346343
if len(listxmiss) > 0:
347-
# sinogram_c[:, listxmiss.get()] = finter(listxmiss.get(), listy.get())
348344
ids = cp.searchsorted(listx, listxmiss)
349-
sinogram[:, listxmiss] = matz[:, ids - 1] + (listxmiss - listx[ids - 1]) * (
350-
matz[:, ids] - matz[:, ids - 1]
351-
) / (listx[ids] - listx[ids - 1])
345+
weights = (listxmiss - listx[ids - 1]) / (listx[ids] - listx[ids - 1])
346+
# direct interpolation without making an extra copy
347+
sinogram[:, listxmiss] = (
348+
sinogram[:, listx[ids - 1]] +
349+
weights * (sinogram[:, listx[ids]] - sinogram[:, listx[ids - 1]])
350+
)
352351

353352
# Remove residual stripes
354353
if norm is True:

0 commit comments

Comments
 (0)