Skip to content

Commit 235dcf1

Browse files
committed
New clip option
1 parent 92cf04a commit 235dcf1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/common_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, default_value=None, *args):
2929
DO_OUTPUT_DEPTH_PREDICTION = False # Hidden, do not use, subject to change
3030

3131
CLIPDEPTH = False
32+
CLIPDEPTH_MODE = "Range"
3233
CLIPDEPTH_FAR = 0.0
3334
CLIPDEPTH_NEAR = 1.0
3435

src/common_ui.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def main_ui_panel(is_depth_tab):
6666
inp -= 'depthmap_gen_row_3', cur_option_root
6767
with gr.Row():
6868
inp += go.CLIPDEPTH, gr.Checkbox(label="Clip and renormalize DepthMap")
69+
inp += go.CLIPDEPTH_MODE,\
70+
gr.Dropdown(label="Mode", choices=['Range', 'Outliers'], type="value", visible=False)
6971
with gr.Row(visible=False) as clip_options_row_1:
7072
inp += go.CLIPDEPTH_FAR, gr.Slider(minimum=0, maximum=1, step=0.001, label='Far clip')
7173
inp += go.CLIPDEPTH_NEAR, gr.Slider(minimum=0, maximum=1, step=0.001, label='Near clip')
@@ -179,6 +181,7 @@ def update_default_net_size(model_type):
179181
inp.add_rule(options_depend_on_output_depth_1, 'visible-if', go.DO_OUTPUT_DEPTH)
180182
inp.add_rule(go.OUTPUT_DEPTH_INVERT, 'visible-if', go.DO_OUTPUT_DEPTH)
181183
inp.add_rule(go.OUTPUT_DEPTH_COMBINE_AXIS, 'visible-if', go.OUTPUT_DEPTH_COMBINE)
184+
inp.add_rule(go.CLIPDEPTH_MODE, 'visible-if', go.CLIPDEPTH)
182185
inp.add_rule(clip_options_row_1, 'visible-if', go.CLIPDEPTH)
183186

184187
inp[go.CLIPDEPTH_FAR].change(

src/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
190190
if inp[go.DO_OUTPUT_DEPTH_PREDICTION]:
191191
yield count, 'depth_prediction', np.copy(out)
192192
if inp[go.CLIPDEPTH]:
193-
out = (out - out.min()) / (out.max() - out.min()) # normalize to [0; 1]
194-
out = np.clip(out, inp[go.CLIPDEPTH_FAR], inp[go.CLIPDEPTH_NEAR])
193+
if inp[go.CLIPDEPTH_MODE] == 'Range':
194+
out = (out - out.min()) / (out.max() - out.min()) # normalize to [0; 1]
195+
out = np.clip(out, inp[go.CLIPDEPTH_FAR], inp[go.CLIPDEPTH_NEAR])
196+
elif inp[go.CLIPDEPTH_MODE] == 'Outliers':
197+
fb, nb = np.percentile(out, [inp[go.CLIPDEPTH_FAR] * 100.0, inp[go.CLIPDEPTH_NEAR] * 100.0])
198+
out = np.clip(out, fb, nb)
195199
out = (out - out.min()) / (out.max() - out.min()) # normalize to [0; 1]
196200
else:
197201
# Regretfully, the depthmap is broken and will be replaced with a black image

0 commit comments

Comments
 (0)