DawnC commited on
Commit
c40071d
·
verified ·
1 Parent(s): 64b10ca

Update ui_manager.py

Browse files
Files changed (1) hide show
  1. ui_manager.py +20 -6
ui_manager.py CHANGED
@@ -635,15 +635,27 @@ class UIManager:
635
  logger.warning(f"Unexpected editor output type: {type(editor_output)}")
636
  return None
637
 
638
- # Convert to grayscale if needed
639
  if len(mask_array.shape) == 3:
640
  if mask_array.shape[2] == 4:
641
- # RGBA - use alpha channel
642
- mask_gray = mask_array[:, :, 3]
643
- else:
644
- # RGB - convert to grayscale
 
 
 
 
 
 
 
 
 
645
  mask_gray = cv2.cvtColor(mask_array, cv2.COLOR_RGB2GRAY)
 
 
646
  else:
 
647
  mask_gray = mask_array
648
 
649
  return Image.fromarray(mask_gray.astype(np.uint8), mode='L')
@@ -840,7 +852,9 @@ class UIManager:
840
  height=300,
841
  brush=gr.Brush(colors=["#FFFFFF"], default_size=20),
842
  eraser=gr.Eraser(default_size=20),
843
- layers=False
 
 
844
  )
845
 
846
  # Template selection
 
635
  logger.warning(f"Unexpected editor output type: {type(editor_output)}")
636
  return None
637
 
638
+ # Convert to grayscale mask
639
  if len(mask_array.shape) == 3:
640
  if mask_array.shape[2] == 4:
641
+ # RGBA format - extract white brush strokes from RGB channels
642
+ # White brush strokes have high RGB values AND high alpha
643
+ rgb_part = mask_array[:, :, :3]
644
+ alpha_part = mask_array[:, :, 3]
645
+
646
+ # Convert RGB to grayscale to detect white areas
647
+ gray = cv2.cvtColor(rgb_part, cv2.COLOR_RGB2GRAY)
648
+
649
+ # Combine: white areas (high gray value) with opacity (high alpha)
650
+ # This captures white brush strokes
651
+ mask_gray = np.minimum(gray, alpha_part)
652
+ elif mask_array.shape[2] == 3:
653
+ # RGB - convert to grayscale (white areas become white in mask)
654
  mask_gray = cv2.cvtColor(mask_array, cv2.COLOR_RGB2GRAY)
655
+ else:
656
+ mask_gray = mask_array[:, :, 0]
657
  else:
658
+ # Already grayscale
659
  mask_gray = mask_array
660
 
661
  return Image.fromarray(mask_gray.astype(np.uint8), mode='L')
 
852
  height=300,
853
  brush=gr.Brush(colors=["#FFFFFF"], default_size=20),
854
  eraser=gr.Eraser(default_size=20),
855
+ layers=True,
856
+ sources=["upload"],
857
+ image_mode="RGBA"
858
  )
859
 
860
  # Template selection