|
10 | 10 | from collections.abc import Sequence |
11 | 11 |
|
12 | 12 | import numpy as np |
13 | | -from scipy.ndimage import gaussian_filter |
14 | 13 |
|
15 | 14 | from pylops.basicoperators import Diagonal, Smoothing2D, SmoothingND |
16 | 15 | from pylops.optimization.leastsquares import preconditioned_inversion |
|
20 | 19 | get_array_module, |
21 | 20 | get_csr_matrix, |
22 | 21 | get_dia_matrix, |
| 22 | + get_gaussian_filter, |
23 | 23 | get_normalize_axis_index, |
24 | 24 | get_toeplitz, |
25 | 25 | ) |
@@ -266,37 +266,39 @@ def slope_estimate( |
266 | 266 | anisotropy in digitized images", Journal ASCI Imaging Workshop. 1995. |
267 | 267 |
|
268 | 268 | """ |
269 | | - slopes = np.zeros_like(d) |
270 | | - anisos = np.zeros_like(d) |
| 269 | + ncp = get_array_module(d) |
271 | 270 |
|
272 | | - gz, gx = np.gradient(d, dz, dx) |
| 271 | + slopes = ncp.zeros_like(d) |
| 272 | + anisos = ncp.zeros_like(d) |
| 273 | + |
| 274 | + gz, gx = ncp.gradient(d, dz, dx) |
273 | 275 | gzz, gzx, gxx = gz * gz, gz * gx, gx * gx |
274 | 276 |
|
275 | 277 | # smoothing |
276 | | - gzz = gaussian_filter(gzz, sigma=smooth) |
277 | | - gzx = gaussian_filter(gzx, sigma=smooth) |
278 | | - gxx = gaussian_filter(gxx, sigma=smooth) |
| 278 | + gzz = get_gaussian_filter(d)(gzz, sigma=smooth) |
| 279 | + gzx = get_gaussian_filter(d)(gzx, sigma=smooth) |
| 280 | + gxx = get_gaussian_filter(d)(gxx, sigma=smooth) |
279 | 281 |
|
280 | | - gmax = max(gzz.max(), gxx.max(), np.abs(gzx).max()) |
| 282 | + gmax = max(gzz.max(), gxx.max(), ncp.abs(gzx).max()) |
281 | 283 | if gmax <= eps: |
282 | | - return np.zeros_like(d), anisos |
| 284 | + return ncp.zeros_like(d), anisos |
283 | 285 |
|
284 | 286 | gzz /= gmax |
285 | 287 | gzx /= gmax |
286 | 288 | gxx /= gmax |
287 | 289 |
|
288 | 290 | lcommon1 = 0.5 * (gzz + gxx) |
289 | | - lcommon2 = 0.5 * np.sqrt((gzz - gxx) ** 2 + 4 * gzx**2) |
| 291 | + lcommon2 = 0.5 * ncp.sqrt((gzz - gxx) ** 2 + 4 * gzx**2) |
290 | 292 | l1 = lcommon1 + lcommon2 |
291 | 293 | l2 = lcommon1 - lcommon2 |
292 | 294 |
|
293 | 295 | regdata = l1 > eps |
294 | 296 | anisos[regdata] = 1 - l2[regdata] / l1[regdata] |
295 | 297 |
|
296 | 298 | if dips: |
297 | | - slopes = 0.5 * np.arctan2(2 * gzx, gzz - gxx) |
| 299 | + slopes = 0.5 * ncp.arctan2(2 * gzx, gzz - gxx) |
298 | 300 | else: |
299 | | - regdata = np.abs(gzx) > eps |
| 301 | + regdata = ncp.abs(gzx) > eps |
300 | 302 | slopes[regdata] = (l1 - gzz)[regdata] / gzx[regdata] |
301 | 303 |
|
302 | 304 | return slopes, anisos |
|
0 commit comments