Skip to content

Commit 8b04d4a

Browse files
committed
Make centering and clamping of cutouts optional.
ABLATION!!!!1
1 parent 880fbbe commit 8b04d4a

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

__init__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def votes_to_detections(locations, probas=None, in_rphi=True, out_rphi=True, bin
218218
return (maxima, grid) if retgrid else maxima
219219

220220

221-
def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distance=1.0, npts=None, border=29.99, resample_type='cv', **kw):
221+
def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distance=1.0, npts=None, center=True, border=29.99, resample_type='cv', **kw):
222222
'''
223223
Generate window cut outs that all have a fixed size independent of depth.
224224
This means areas close to the scanner will be subsampled and areas far away
@@ -230,9 +230,10 @@ def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distan
230230
- `standard_depth` the reference distance (in meters) at which a window with `window_size` gets cut out.
231231
- `window_size` the window of laser rays that will be extracted everywhere.
232232
- `npts` is the number of final samples to have per window. `None` means same as `window_size`.
233-
- `threshold_distance` the distance in meters from the center point that will be
234-
used to clamp the laser radii. Since we're talking about laser-radii, this means the cutout is
235-
a donut-shaped hull, as opposed to a rectangular hull.
233+
- `threshold_distance` the distance in meters from the center point that will be used to clamp the laser radii.
234+
Since we're talking about laser-radii, this means the cutout is a donut-shaped hull, as opposed to a rectangular hull.
235+
This can be `np.inf` to skip the clamping altogether.
236+
- `center` whether to center the cutout around the current laser point's depth (True), or keep depth values raw (False).
236237
- `border` the radius value to fill the half of the outermost windows with.
237238
- `resample_type` specifies the resampling API to be used. Possible values are:
238239
- `cv` for OpenCV's `cv2.resize` function using LINEAR/AREA interpolation.
@@ -248,10 +249,13 @@ def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distan
248249
current_size = (window_size * standard_depth / s_np).astype(np.int32)
249250
start = -current_size//2 + np.arange(N)
250251
end = start + current_size
251-
near = s_np-threshold_distance
252-
far = s_np+threshold_distance
253252
s_np_extended = np.append(s_np, border)
254253

254+
# While we don't really need to special-case, it should save precious computation.
255+
if threshold_distance != np.inf:
256+
near = s_np-threshold_distance
257+
far = s_np+threshold_distance
258+
255259
for i in range(N):
256260
# Get the window.
257261
sample_points = np.arange(start[i], end[i])
@@ -260,9 +264,14 @@ def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distan
260264
window = s_np_extended[sample_points]
261265

262266
# Threshold the near and far values, then
267+
if threshold_distance != np.inf:
268+
window = np.clip(window, near[i], far[i])
269+
263270
# shift everything to be centered around the middle point.
264-
# Values will then span [-d,d]
265-
window = np.clip(window, near[i], far[i]) - s_np[i]
271+
if center:
272+
window -= s_np[i]
273+
274+
# Values will now span [-d,d] if `center` and `clamp` are both True.
266275

267276
# resample it to the correct size.
268277
if resample_type == 'cv':

0 commit comments

Comments
 (0)