@@ -102,9 +102,8 @@ def ui(self, is_img2img):
102
102
show_heat = gr .Checkbox (label = "Show HeatMap" ,value = False )
103
103
with gr .Group ():
104
104
with gr .Row ():
105
- gen_stereo = gr .Checkbox (label = "Generate Stereo side-by-side image" ,value = False )
106
- gen_stereotb = gr .Checkbox (label = "Generate Stereo top-bottom image" ,value = False )
107
- gen_anaglyph = gr .Checkbox (label = "Generate Stereo anaglyph image (red/cyan)" ,value = False )
105
+ gen_stereo = gr .Checkbox (label = "Generate stereoscopic image" , value = False )
106
+ stereo_mode = gr .Dropdown (label = "Stereoscopic image type" , choices = ['left-right' , 'right-left' , 'top-bottom' , 'bottom-top' , 'red-cyan-anaglyph' ], value = 'left-right' , type = "value" , elem_id = "stereo_mode" )
108
107
with gr .Row ():
109
108
stereo_divergence = gr .Slider (minimum = 0.05 , maximum = 10.005 , step = 0.01 , label = 'Divergence (3D effect)' , value = 2.5 )
110
109
with gr .Row ():
@@ -140,10 +139,10 @@ def ui(self, is_img2img):
140
139
outputs = [clipthreshold_far ]
141
140
)
142
141
143
- 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 ]
142
+ 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 , stereo_mode , 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
143
145
144
# run from script in txt2img or img2img
146
- 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 ):
145
+ 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 , stereo_mode , 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 ):
147
146
148
147
# sd process
149
148
processed = processing .process_images (p )
@@ -166,14 +165,14 @@ def run(self, p, compute_device, model_type, net_width, net_height, match_size,
166
165
else :
167
166
background_removed_images = batched_background_removal (inputimages , background_removal_model )
168
167
169
- 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 )
168
+ 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 , stereo_mode , 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 )
170
169
171
170
for img in newmaps :
172
171
processed .images .append (img )
173
172
174
173
return processed
175
174
176
- 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 ):
175
+ 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 , stereo_mode , 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 ):
177
176
178
177
if len (inputimages ) == 0 or inputimages [0 ] == None :
179
178
return []
@@ -464,50 +463,22 @@ def run_depthmap(processed, outpath, inputimages, inputnames, compute_device, mo
464
463
heatmap = (colormap (img_output2 [:,:,0 ] / 256.0 ) * 2 ** 16 ).astype (np .uint16 )[:,:,:3 ]
465
464
outimages .append (heatmap )
466
465
467
- if gen_stereo or gen_stereotb or gen_anaglyph :
468
- print ("Generating Stereo image.." )
469
- #img_output = cv2.blur(img_output, (3, 3))
470
- balance = (stereo_balance + 1 ) / 2
471
- original_image = np .asarray (inputimages [count ])
472
- left_image = original_image if balance < 0.001 else \
473
- apply_stereo_divergence (original_image , img_output , - stereo_divergence * balance , stereo_fill )
474
- right_image = original_image if balance > 0.999 else \
475
- apply_stereo_divergence (original_image , img_output , stereo_divergence * (1 - balance ), stereo_fill )
476
- stereo_img = np .hstack ([left_image , right_image ])
477
- stereotb_img = np .vstack ([left_image , right_image ])
478
-
479
- # flip sbs left/right if enabled in settings
480
- if hasattr (opts , 'depthmap_script_sbsflip' ):
481
- if opts .depthmap_script_sbsflip :
482
- stereo_img = np .hstack ([right_image , left_image ])
483
- stereotb_img = np .vstack ([right_image , left_image ])
484
-
485
- if gen_stereo :
486
- outimages .append (stereo_img )
487
- if gen_stereotb :
488
- outimages .append (stereotb_img )
489
- if gen_anaglyph :
490
- print ("Generating Anaglyph image.." )
491
- anaglyph_img = overlap_red_cyan (left_image , right_image )
492
- outimages .append (anaglyph_img )
493
- if (processed is not None ):
494
- if gen_stereo :
495
- 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" )
496
- if gen_stereotb :
497
- 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" )
498
- if gen_anaglyph :
499
- 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" )
466
+ if gen_stereo :
467
+ print ("Generating stereoscopic image(s).." )
468
+ stereoimage = create_stereoimage (inputimages [count ], img_output , stereo_divergence , stereo_mode , stereo_balance , stereo_fill )
469
+ outimages .append (stereoimage )
470
+
471
+ if processed is not None :
472
+ images .save_image (stereoimage , outpath , "" , processed .all_seeds [count ],
473
+ processed .all_prompts [count ], opts .samples_format , info = info , p = processed ,
474
+ suffix = f"_{ stereo_mode } " )
500
475
else :
501
476
# from tab
502
- if gen_stereo :
503
- 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" )
504
- if gen_stereotb :
505
- 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" )
506
- if gen_anaglyph :
507
- 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" )
477
+ images .save_image (stereoimage , path = outpath , basename = basename , seed = None ,
478
+ prompt = None , extension = opts .samples_format , info = info , short_filename = True ,
479
+ no_prompt = True , grid = False , pnginfo_section_name = "extras" , existing_info = None ,
480
+ forced_filename = None , suffix = f"_{ stereo_mode } " )
508
481
509
-
510
-
511
482
if gen_normal :
512
483
# taken from @graemeniedermayer, hidden, for api use only, will remove in future
513
484
# take gradients
@@ -873,9 +844,8 @@ def run_generate(depthmap_mode,
873
844
show_heat ,
874
845
combine_output ,
875
846
combine_output_axis ,
876
- gen_stereo ,
877
- gen_stereotb ,
878
- gen_anaglyph ,
847
+ gen_stereo ,
848
+ stereo_mode ,
879
849
stereo_divergence ,
880
850
stereo_fill ,
881
851
stereo_balance ,
@@ -937,16 +907,15 @@ def run_generate(depthmap_mode,
937
907
imageArr = batched_background_removal (imageArr , background_removal_model )
938
908
background_removed_images = imageArr
939
909
else :
940
- background_removed_images = batched_background_removal (imageArr , background_removal_model )
910
+ background_removed_images = batched_background_removal (imageArr , background_removal_model )
941
911
942
- 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 )
912
+ 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 , stereo_mode , 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 )
943
913
944
914
return outputs , mesh_fi , plaintext_to_html ('info' ), ''
945
915
946
916
def on_ui_settings ():
947
917
section = ('depthmap-script' , "Depthmap extension" )
948
918
shared .opts .add_option ("depthmap_script_boost_rmax" , shared .OptionInfo (1600 , "Maximum wholesize for boost" , section = section ))
949
- shared .opts .add_option ("depthmap_script_sbsflip" , shared .OptionInfo (False , "Flip Left/Right in SBS stereo images (requested for cross-eyed viewing)" , section = section ))
950
919
951
920
def on_ui_tabs ():
952
921
with gr .Blocks (analytics_enabled = False ) as depthmap_interface :
@@ -994,9 +963,8 @@ def on_ui_tabs():
994
963
show_heat = gr .Checkbox (label = "Show HeatMap" ,value = False )
995
964
with gr .Group ():
996
965
with gr .Row ():
997
- gen_stereo = gr .Checkbox (label = "Generate Stereo side-by-side image" ,value = False )
998
- gen_stereotb = gr .Checkbox (label = "Generate Stereo top-bottom image" ,value = False )
999
- gen_anaglyph = gr .Checkbox (label = "Generate Stereo anaglyph image (red/cyan)" ,value = False )
966
+ gen_stereo = gr .Checkbox (label = "Generate stereoscopic image" ,value = False )
967
+ stereo_mode = gr .Dropdown (label = "Stereoscopic image type" , choices = ['left-right' , 'right-left' , 'top-bottom' , 'bottom-top' , 'red-cyan-anaglyph' ], value = 'left-right' , type = "value" , elem_id = "stereo_mode" )
1000
968
with gr .Row ():
1001
969
stereo_divergence = gr .Slider (minimum = 0.05 , maximum = 10.005 , step = 0.01 , label = 'Divergence (3D effect)' , value = 2.5 )
1002
970
with gr .Row ():
@@ -1080,9 +1048,8 @@ def on_ui_tabs():
1080
1048
show_heat ,
1081
1049
combine_output ,
1082
1050
combine_output_axis ,
1083
- gen_stereo ,
1084
- gen_stereotb ,
1085
- gen_anaglyph ,
1051
+ gen_stereo ,
1052
+ stereo_mode ,
1086
1053
stereo_divergence ,
1087
1054
stereo_fill ,
1088
1055
stereo_balance ,
0 commit comments