LogicGoInfotechSpaces commited on
Commit
0e28031
·
1 Parent(s): 8c6db4d

fix: correct invert_mask logic - RGB masks already have white=remove, only invert if invert_mask=False explicitly requested

Browse files
Files changed (1) hide show
  1. src/core.py +11 -6
src/core.py CHANGED
@@ -490,18 +490,23 @@ def process_inpaint(image, mask, invert_mask=True):
490
  mask = 255 - alpha_channel
491
  transparent_count = int((alpha_channel < 128).sum())
492
  print(f"Using alpha channel: {transparent_count} transparent pixels → white (to remove)")
 
 
 
 
 
493
  else:
494
  # Alpha is mostly opaque (255), use RGB channels instead
495
- # RGB masks: white (255) = remove, black (0) = keep
496
  gray = cv2.cvtColor(rgb_channels, cv2.COLOR_RGB2GRAY)
497
  mask = (gray > 128).astype(np.uint8) * 255
498
  white_count = int((mask > 128).sum())
499
  print(f"Using RGB channels: {white_count} white pixels (to remove)")
500
-
501
- # Apply invert_mask if user wants opposite behavior
502
- if not invert_mask:
503
- mask = 255 - mask # invert: white becomes black, black becomes white
504
- print(f"Applied invert_mask=False: inverted mask")
505
 
506
  # Resize mask to match image dimensions
507
  if size_limit < max_dimension:
 
490
  mask = 255 - alpha_channel
491
  transparent_count = int((alpha_channel < 128).sum())
492
  print(f"Using alpha channel: {transparent_count} transparent pixels → white (to remove)")
493
+ # For alpha-based masks: invert_mask=True means keep current (white=remove is correct)
494
+ # invert_mask=False means invert (white becomes black)
495
+ if not invert_mask:
496
+ mask = 255 - mask
497
+ print(f"Applied invert_mask=False: inverted alpha-based mask")
498
  else:
499
  # Alpha is mostly opaque (255), use RGB channels instead
500
+ # RGB masks: white (255) = remove, black (0) = keep (standard convention)
501
  gray = cv2.cvtColor(rgb_channels, cv2.COLOR_RGB2GRAY)
502
  mask = (gray > 128).astype(np.uint8) * 255
503
  white_count = int((mask > 128).sum())
504
  print(f"Using RGB channels: {white_count} white pixels (to remove)")
505
+ # For RGB-based masks: white=remove is already correct
506
+ # invert_mask=False means we want black=remove (invert it)
507
+ if not invert_mask:
508
+ mask = 255 - mask # invert: white becomes black, black becomes white
509
+ print(f"Applied invert_mask=False: inverted RGB mask (now black=remove)")
510
 
511
  # Resize mask to match image dimensions
512
  if size_limit < max_dimension: