@@ -321,41 +321,44 @@ def clean_image(R, n=3, thr=0):
321
321
R [mask ] = np .nanmin (R )
322
322
323
323
return R
324
-
324
+
325
325
def declustering (x , y , u , v , decl_grid , min_nr_samples ):
326
- """
327
- Filter out outliers and get more representative data points.
328
- It assigns data points to a (RxR) declustering grid and then take the median of all values within one cell.
326
+ """Filter out outliers in a sparse motion field and get more representative
327
+ data points. The method assigns data points to a (RxR) declustering grid
328
+ and then take the median of all values within one cell.
329
329
330
330
Parameters
331
331
----------
332
- x0 :
333
- y0 :
334
- u :
335
- v :
332
+ x : array_like
333
+ x-coordinates of the origins of the velocity vectors
334
+ y : array_like
335
+ y-coordinates of the origins of the velocity vectors
336
+ u : array_like
337
+ x-components of the velocities
338
+ v : array_like
339
+ y-components of the velocities
336
340
decl_grid : int
337
- Size of the declustering grid [px].
341
+ size of the declustering grid [px]
338
342
min_nr_samples : int
339
- The minimum number of samples for computing the median within given declustering cell.
340
-
343
+ the minimum number of samples for computing the median within given
344
+ declustering cell
345
+
341
346
Returns
342
347
-------
343
- x : array-like
344
- y : array-like
345
- u : array-like
346
- v : array-like
347
-
348
+ A four-element tuple (x,y,u,v) containing the x- and y-coordinates and
349
+ velocity components of the declustered motion vectors.
350
+
348
351
"""
349
352
# make sure these are all vertical arrays
350
353
x = x [:,None ]
351
354
y = y [:,None ]
352
355
u = u [:,None ]
353
356
v = v [:,None ]
354
-
357
+
355
358
# discretize coordinates into declustering grid
356
359
xT = x / float (decl_grid )
357
360
yT = y / float (decl_grid )
358
-
361
+
359
362
# round coordinates to low integer
360
363
xT = np .floor (xT )
361
364
yT = np .floor (yT )
@@ -366,7 +369,8 @@ def declustering(x, y, u, v, decl_grid, min_nr_samples):
366
369
_ ,idx = np .unique (xyb , return_index = True )
367
370
unique_xy = xy [idx ]
368
371
369
- # now loop through these unique values and average vectors which belong to the same declustering grid cell
372
+ # now loop through these unique values and average vectors which belong to
373
+ # the same declustering grid cell
370
374
xN = []; yN = []; uN = []; vN = []
371
375
for i in range (unique_xy .shape [0 ]):
372
376
idx = np .logical_and (xT == unique_xy [i ,0 ], yT == unique_xy [i ,1 ])
0 commit comments