MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / process_predicitons

Function process_predicitons

src/video_mode.py:103–128  ·  view source on GitHub ↗
(predictions, smoothening='none')

Source from the content-addressed store, hash-verified

101
102
103def process_predicitons(predictions, smoothening='none'):
104 def global_scaling(objs, a=None, b=None):
105 """Normalizes objs, but uses (a, b) instead of (minimum, maximum) value of objs, if supplied"""
106 normalized = []
107 min_value = a if a is not None else min([obj.min() for obj in objs])
108 max_value = b if b is not None else max([obj.max() for obj in objs])
109 for obj in objs:
110 normalized += [(obj - min_value) / (max_value - min_value)]
111 return normalized
112
113 print('Processing generated depthmaps')
114 # TODO: Detect cuts and process segments separately
115 if smoothening == 'none':
116 return global_scaling(predictions)
117 elif smoothening == 'experimental':
118 processed = []
119 clip = lambda val: min(max(0, val), len(predictions) - 1)
120 for i in range(len(predictions)):
121 f = np.zeros_like(predictions[i])
122 for u, mul in enumerate([0.10, 0.20, 0.40, 0.20, 0.10]): # Eyeballed it, math person please fix this
123 f += mul * predictions[clip(i + (u - 2))]
124 processed += [f]
125 # This could have been deterministic monte carlo... Oh well, this version is faster.
126 a, b = np.percentile(np.stack(processed), [0.5, 99.5])
127 return global_scaling(predictions, a, b)
128 return predictions
129
130
131def gen_video(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None, smoothening='none'):

Callers 1

gen_videoFunction · 0.85

Calls 1

global_scalingFunction · 0.85

Tested by

no test coverage detected