saliacoel commited on
Commit
e636647
·
verified ·
1 Parent(s): e5f38c6

Update rbga_to_black_bg.py

Browse files
Files changed (1) hide show
  1. rbga_to_black_bg.py +5 -5
rbga_to_black_bg.py CHANGED
@@ -2,7 +2,7 @@ import torch
2
 
3
  class RGBA_Black_Background:
4
  """
5
- Composites an RGBA image over a white background and outputs RGB.
6
  Assumes input image in ComfyUI tensor format: float32, 0..1, shape [B,H,W,C].
7
  """
8
 
@@ -37,10 +37,10 @@ class RGBA_Black_Background:
37
  raise ValueError(f"Expected 3 (RGB) or 4 (RGBA) channels, got {c}")
38
 
39
  rgb = image[..., :3]
40
- a = image[..., 3:4] # keep as [B,H,W,1]
41
 
42
- # Composite: out = rgb * a + white * (1-a) ; white=1
43
- out = rgb * a + (0.0 - a)
44
 
45
  return (out.clamp(0.0, 1.0),)
46
 
@@ -51,4 +51,4 @@ NODE_CLASS_MAPPINGS = {
51
 
52
  NODE_DISPLAY_NAME_MAPPINGS = {
53
  "RGBA_Black_Background": "RGBA to Black Background RGB (Black Background)"
54
- }
 
2
 
3
  class RGBA_Black_Background:
4
  """
5
+ Composites an RGBA image over a black background and outputs RGB.
6
  Assumes input image in ComfyUI tensor format: float32, 0..1, shape [B,H,W,C].
7
  """
8
 
 
37
  raise ValueError(f"Expected 3 (RGB) or 4 (RGBA) channels, got {c}")
38
 
39
  rgb = image[..., :3]
40
+ a = image[..., 3:4] # [B,H,W,1]
41
 
42
+ # Black background composite: bg=0 => out = rgb*a + 0*(1-a) = rgb*a
43
+ out = rgb * a
44
 
45
  return (out.clamp(0.0, 1.0),)
46
 
 
51
 
52
  NODE_DISPLAY_NAME_MAPPINGS = {
53
  "RGBA_Black_Background": "RGBA to Black Background RGB (Black Background)"
54
+ }