@@ -85,6 +85,10 @@ def batch2list(tensor_batch):
8585 return tensors
8686
8787
88+ def list2batch (tensor_list ):
89+ return torch .cat (tensor_list )
90+
91+
8892def rgba2rgb (pil ):
8993 bg = Image .new ("RGB" , pil .size , (255 , 255 , 255 ))
9094 bg .paste (pil , pil )
@@ -442,6 +446,37 @@ def node_function(self, directory, recursive, channels):
442446 return (out_image , out_dir , out_name )
443447
444448
449+ class LoadImageBatchFromDirectoryNode :
450+ def __init__ (self ):
451+ pass
452+
453+ @classmethod
454+ def INPUT_TYPES (cls ):
455+ return {
456+ "required" : {
457+ "directory" : (IO .STRING , {"default" : "" , "forceInput" : False }),
458+ "recursive" : (IO .BOOLEAN , {"default" : False }),
459+ "channels" : (["RGB" , "RGBA" ], {"default" : "RGB" }),
460+ }
461+ }
462+
463+ FUNCTION = "node_function"
464+ CATEGORY = "Fair/image"
465+
466+ RETURN_TYPES = (IO .IMAGE , IO .STRING , IO .STRING )
467+ RETURN_NAMES = ("images" , "directory" , "name" )
468+ OUTPUT_IS_LIST = (False , True , True )
469+
470+ def node_function (self , directory , recursive , channels ):
471+ if not directory or not os .path .isdir (directory ):
472+ raise Exception ("folder_path is not valid: " + directory )
473+
474+ (out_image , out_dir , out_name ) = load_image_to_tensor (directory , recursive , channels )
475+ out_image = list2batch (out_image )
476+
477+ return (out_image , out_dir , out_name )
478+
479+
445480class FillAlphaNode :
446481 def __init__ (self ):
447482 pass
@@ -485,21 +520,8 @@ def fill_alpha(self, tensor, alpha_threshold, fill_color):
485520 return image_tensor
486521
487522 def node_function (self , image , alpha_threshold , r , g , b ):
488- height = image [0 ].shape [0 ]
489- width = image [0 ].shape [1 ]
490-
491- progress_bar = ProgressBar (image .shape [0 ])
492-
493- image_tensors = []
494-
495- for tensor in batch2list (image ):
496- tensor_filled = self .fill_alpha (tensor , alpha_threshold , (r , g , b ))
497- image_tensors .append (tensor_filled )
498- progress_bar .update (1 )
499-
500- image_tensors = tensor2batch (image_tensors , height , width , 3 )
501-
502- return (image_tensors ,)
523+ tensor_filled = self .fill_alpha (image , alpha_threshold , (r , g , b ))
524+ return (tensor_filled ,)
503525
504526
505527def pil_to_base64 (pli_image , pnginfo = None , header = False ):
0 commit comments