Skip to content

Commit 33a9379

Browse files
authored
Merge pull request #133 from scruffynerf/main
add stereotb option and support code
2 parents 7e2d005 + 7f52895 commit 33a9379

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

scripts/depthmap.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def ui(self, is_img2img):
101101
with gr.Group():
102102
with gr.Row():
103103
gen_stereo = gr.Checkbox(label="Generate Stereo side-by-side image",value=False)
104+
gen_stereotb = gr.Checkbox(label="Generate Stereo top-bottom image",value=False)
104105
gen_anaglyph = gr.Checkbox(label="Generate Stereo anaglyph image (red/cyan)",value=False)
105106
with gr.Row():
106107
stereo_divergence = gr.Slider(minimum=0.05, maximum=10.005, step=0.01, label='Divergence (3D effect)', value=2.5)
@@ -137,10 +138,10 @@ def ui(self, is_img2img):
137138
outputs=[clipthreshold_far]
138139
)
139140

140-
return [compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, background_removal_model, background_removal, pre_depth_background_removal, save_background_removal_masks, gen_normal]
141+
return [compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_stereotb, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, background_removal_model, background_removal, pre_depth_background_removal, save_background_removal_masks, gen_normal]
141142

142143
# run from script in txt2img or img2img
143-
def run(self, p, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, background_removal_model, background_removal, pre_depth_background_removal, save_background_removal_masks, gen_normal):
144+
def run(self, p, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_stereotb, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, background_removal_model, background_removal, pre_depth_background_removal, save_background_removal_masks, gen_normal):
144145

145146
# sd process
146147
processed = processing.process_images(p)
@@ -163,14 +164,14 @@ def run(self, p, compute_device, model_type, net_width, net_height, match_size,
163164
else:
164165
background_removed_images = batched_background_removal(inputimages, background_removal_model)
165166

166-
newmaps, mesh_fi = run_depthmap(processed, p.outpath_samples, inputimages, None, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, "mp4", 0, background_removal, background_removed_images, save_background_removal_masks, gen_normal)
167+
newmaps, mesh_fi = run_depthmap(processed, p.outpath_samples, inputimages, None, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_stereotb, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, "mp4", 0, background_removal, background_removed_images, save_background_removal_masks, gen_normal)
167168

168169
for img in newmaps:
169170
processed.images.append(img)
170171

171172
return processed
172173

173-
def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, fnExt, vid_ssaa, background_removal, background_removed_images, save_background_removal_masks, gen_normal):
174+
def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_stereotb, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, fnExt, vid_ssaa, background_removal, background_removed_images, save_background_removal_masks, gen_normal):
174175

175176
if len(inputimages) == 0 or inputimages[0] == None:
176177
return []
@@ -461,7 +462,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, mo
461462
heatmap = (colormap(img_output2[:,:,0] / 256.0) * 2**16).astype(np.uint16)[:,:,:3]
462463
outimages.append(heatmap)
463464

464-
if gen_stereo or gen_anaglyph:
465+
if gen_stereo or gen_stereotb or gen_anaglyph:
465466
print("Generating Stereo image..")
466467
#img_output = cv2.blur(img_output, (3, 3))
467468
balance = (stereo_balance + 1) / 2
@@ -471,27 +472,35 @@ def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, mo
471472
right_image = original_image if balance > 0.999 else \
472473
apply_stereo_divergence(original_image, img_output, stereo_divergence * (1 - balance), stereo_fill)
473474
stereo_img = np.hstack([left_image, right_image])
475+
stereotb_img = np.vstack([left_image, right_image])
474476

475477
# flip sbs left/right if enabled in settings
476478
if hasattr(opts, 'depthmap_script_sbsflip'):
477479
if opts.depthmap_script_sbsflip:
478480
stereo_img = np.hstack([right_image, left_image])
481+
stereotb_img = np.vstack([right_image, left_image])
479482

480483
if gen_stereo:
481484
outimages.append(stereo_img)
485+
if gen_stereotb:
486+
outimages.append(stereotb_img)
482487
if gen_anaglyph:
483488
print("Generating Anaglyph image..")
484489
anaglyph_img = overlap(left_image, right_image)
485490
outimages.append(anaglyph_img)
486491
if (processed is not None):
487492
if gen_stereo:
488493
images.save_image(Image.fromarray(stereo_img), outpath, "", processed.all_seeds[count], processed.all_prompts[count], opts.samples_format, info=info, p=processed, suffix="_stereo")
494+
if gen_stereotb:
495+
images.save_image(Image.fromarray(stereotb_img), outpath, "", processed.all_seeds[count], processed.all_prompts[count], opts.samples_format, info=info, p=processed, suffix="_stereotb")
489496
if gen_anaglyph:
490497
images.save_image(Image.fromarray(anaglyph_img), outpath, "", processed.all_seeds[count], processed.all_prompts[count], opts.samples_format, info=info, p=processed, suffix="_anaglyph")
491498
else:
492499
# from tab
493500
if gen_stereo:
494501
images.save_image(Image.fromarray(stereo_img), path=outpath, basename=basename, seed=None, prompt=None, extension=opts.samples_format, info=info, short_filename=True,no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=None, forced_filename=None, suffix="_stereo")
502+
if gen_stereotb:
503+
images.save_image(Image.fromarray(stereotb_img), path=outpath, basename=basename, seed=None, prompt=None, extension=opts.samples_format, info=info, short_filename=True,no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=None, forced_filename=None, suffix="_stereotb")
495504
if gen_anaglyph:
496505
images.save_image(Image.fromarray(anaglyph_img), path=outpath, basename=basename, seed=None, prompt=None, extension=opts.samples_format, info=info, short_filename=True,no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=None, forced_filename=None, suffix="_anaglyph")
497506

@@ -1081,6 +1090,7 @@ def run_generate(depthmap_mode,
10811090
combine_output,
10821091
combine_output_axis,
10831092
gen_stereo,
1093+
gen_stereotb,
10841094
gen_anaglyph,
10851095
stereo_divergence,
10861096
stereo_fill,
@@ -1145,7 +1155,7 @@ def run_generate(depthmap_mode,
11451155
else:
11461156
background_removed_images = batched_background_removal(imageArr, background_removal_model)
11471157

1148-
outputs, mesh_fi = run_depthmap(None, outpath, imageArr, imageNameArr, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, fnExt, vid_ssaa, background_removal, background_removed_images, save_background_removal_masks, False)
1158+
outputs, mesh_fi = run_depthmap(None, outpath, imageArr, imageNameArr, compute_device, model_type, net_width, net_height, match_size, invert_depth, boost, save_depth, show_depth, show_heat, combine_output, combine_output_axis, gen_stereo, gen_stereotb, gen_anaglyph, stereo_divergence, stereo_fill, stereo_balance, clipdepth, clipthreshold_far, clipthreshold_near, inpaint, inpaint_vids, fnExt, vid_ssaa, background_removal, background_removed_images, save_background_removal_masks, False)
11491159

11501160
return outputs, mesh_fi, plaintext_to_html('info'), ''
11511161

@@ -1201,6 +1211,7 @@ def on_ui_tabs():
12011211
with gr.Group():
12021212
with gr.Row():
12031213
gen_stereo = gr.Checkbox(label="Generate Stereo side-by-side image",value=False)
1214+
gen_stereotb = gr.Checkbox(label="Generate Stereo top-bottom image",value=False)
12041215
gen_anaglyph = gr.Checkbox(label="Generate Stereo anaglyph image (red/cyan)",value=False)
12051216
with gr.Row():
12061217
stereo_divergence = gr.Slider(minimum=0.05, maximum=10.005, step=0.01, label='Divergence (3D effect)', value=2.5)
@@ -1286,6 +1297,7 @@ def on_ui_tabs():
12861297
combine_output,
12871298
combine_output_axis,
12881299
gen_stereo,
1300+
gen_stereotb,
12891301
gen_anaglyph,
12901302
stereo_divergence,
12911303
stereo_fill,

0 commit comments

Comments
 (0)