@@ -101,6 +101,7 @@ def ui(self, is_img2img):
101
101
with gr .Group ():
102
102
with gr .Row ():
103
103
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 )
104
105
gen_anaglyph = gr .Checkbox (label = "Generate Stereo anaglyph image (red/cyan)" ,value = False )
105
106
with gr .Row ():
106
107
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):
137
138
outputs = [clipthreshold_far ]
138
139
)
139
140
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 ]
141
142
142
143
# 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 ):
144
145
145
146
# sd process
146
147
processed = processing .process_images (p )
@@ -163,14 +164,14 @@ def run(self, p, compute_device, model_type, net_width, net_height, match_size,
163
164
else :
164
165
background_removed_images = batched_background_removal (inputimages , background_removal_model )
165
166
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 )
167
168
168
169
for img in newmaps :
169
170
processed .images .append (img )
170
171
171
172
return processed
172
173
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 ):
174
175
175
176
if len (inputimages ) == 0 or inputimages [0 ] == None :
176
177
return []
@@ -461,7 +462,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, mo
461
462
heatmap = (colormap (img_output2 [:,:,0 ] / 256.0 ) * 2 ** 16 ).astype (np .uint16 )[:,:,:3 ]
462
463
outimages .append (heatmap )
463
464
464
- if gen_stereo or gen_anaglyph :
465
+ if gen_stereo or gen_stereotb or gen_anaglyph :
465
466
print ("Generating Stereo image.." )
466
467
#img_output = cv2.blur(img_output, (3, 3))
467
468
balance = (stereo_balance + 1 ) / 2
@@ -471,27 +472,35 @@ def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, mo
471
472
right_image = original_image if balance > 0.999 else \
472
473
apply_stereo_divergence (original_image , img_output , stereo_divergence * (1 - balance ), stereo_fill )
473
474
stereo_img = np .hstack ([left_image , right_image ])
475
+ stereotb_img = np .vstack ([left_image , right_image ])
474
476
475
477
# flip sbs left/right if enabled in settings
476
478
if hasattr (opts , 'depthmap_script_sbsflip' ):
477
479
if opts .depthmap_script_sbsflip :
478
480
stereo_img = np .hstack ([right_image , left_image ])
481
+ stereotb_img = np .vstack ([right_image , left_image ])
479
482
480
483
if gen_stereo :
481
484
outimages .append (stereo_img )
485
+ if gen_stereotb :
486
+ outimages .append (stereotb_img )
482
487
if gen_anaglyph :
483
488
print ("Generating Anaglyph image.." )
484
489
anaglyph_img = overlap (left_image , right_image )
485
490
outimages .append (anaglyph_img )
486
491
if (processed is not None ):
487
492
if gen_stereo :
488
493
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" )
489
496
if gen_anaglyph :
490
497
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" )
491
498
else :
492
499
# from tab
493
500
if gen_stereo :
494
501
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" )
495
504
if gen_anaglyph :
496
505
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" )
497
506
@@ -1081,6 +1090,7 @@ def run_generate(depthmap_mode,
1081
1090
combine_output ,
1082
1091
combine_output_axis ,
1083
1092
gen_stereo ,
1093
+ gen_stereotb ,
1084
1094
gen_anaglyph ,
1085
1095
stereo_divergence ,
1086
1096
stereo_fill ,
@@ -1145,7 +1155,7 @@ def run_generate(depthmap_mode,
1145
1155
else :
1146
1156
background_removed_images = batched_background_removal (imageArr , background_removal_model )
1147
1157
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 )
1149
1159
1150
1160
return outputs , mesh_fi , plaintext_to_html ('info' ), ''
1151
1161
@@ -1201,6 +1211,7 @@ def on_ui_tabs():
1201
1211
with gr .Group ():
1202
1212
with gr .Row ():
1203
1213
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 )
1204
1215
gen_anaglyph = gr .Checkbox (label = "Generate Stereo anaglyph image (red/cyan)" ,value = False )
1205
1216
with gr .Row ():
1206
1217
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():
1286
1297
combine_output ,
1287
1298
combine_output_axis ,
1288
1299
gen_stereo ,
1300
+ gen_stereotb ,
1289
1301
gen_anaglyph ,
1290
1302
stereo_divergence ,
1291
1303
stereo_fill ,
0 commit comments