Candle commited on
Commit
6ba27a6
·
1 Parent(s): 832ee48
Files changed (1) hide show
  1. correct_fgr.py +18 -16
correct_fgr.py CHANGED
@@ -105,30 +105,29 @@ def process_foreground_correction(expanded_path, automatte_path, output_path):
105
  # Step 1: Alpha channel is already loaded from automatte
106
  alpha = automatte_img.copy()
107
 
108
- # Step 2: Apply thresholding (white = anything >253, black otherwise)
109
- thresholded_alpha = apply_threshold(alpha, threshold=253)
110
-
111
- # # DO NOT COMMIT: save alpha and exit
112
- # cv2.imwrite("debug_alpha.png", alpha)
113
- # import sys; sys.exit(0)
114
-
115
  # Step 3: Contract the alpha channel 1px
116
- contracted_alpha = contract_alpha(thresholded_alpha, pixels=1)
 
117
 
118
- # # DO NOT COMMIT: save alpha and exit
119
- # cv2.imwrite("debug_contracted_alpha.png", alpha)
120
- # import sys; sys.exit(0)
121
-
122
  # Step 4: Invert selection
123
  selection_mask = invert_selection(contracted_alpha)
124
 
 
 
 
125
  # # DO NOT COMMIT: save alpha and exit
126
- # cv2.imwrite("debug_inverted_alpha.png", selection_mask)
 
 
 
 
 
 
127
  # import sys; sys.exit(0)
128
 
129
- # Step 5: Apply minimum filter to RGB image using the selection mask
130
- filtered_rgb = apply_minimum_filter_to_rgb(expanded_img, selection_mask, radius=4)
131
-
132
  # Apply the original contracted alpha (before inversion) to the filtered RGB image
133
  # Convert to RGBA
134
  expanded_rgba = cv2.cvtColor(filtered_rgb, cv2.COLOR_BGR2BGRA)
@@ -157,6 +156,9 @@ def find_matching_pairs():
157
  expanded_pattern = os.path.join(expanded_base, "*", "*.png")
158
  expanded_files = glob.glob(expanded_pattern)
159
 
 
 
 
160
  for expanded_path in expanded_files:
161
  # Extract relative path from expanded base
162
  rel_path = os.path.relpath(expanded_path, expanded_base)
 
105
  # Step 1: Alpha channel is already loaded from automatte
106
  alpha = automatte_img.copy()
107
 
108
+ # Step 2: Apply thresholding (white = anything >235, black otherwise)
109
+ thresholded_alpha = apply_threshold(alpha, threshold=235)
110
+
 
 
 
 
111
  # Step 3: Contract the alpha channel 1px
112
+ # contracted_alpha = contract_alpha(thresholded_alpha, pixels=0)
113
+ contracted_alpha = thresholded_alpha
114
 
 
 
 
 
115
  # Step 4: Invert selection
116
  selection_mask = invert_selection(contracted_alpha)
117
 
118
+ # Step 5: Apply minimum filter to RGB image using the selection mask
119
+ filtered_rgb = apply_minimum_filter_to_rgb(expanded_img, selection_mask, radius=2)
120
+
121
  # # DO NOT COMMIT: save alpha and exit
122
+ # cv2.imwrite("debug_expanded.png", expanded_img)
123
+ # cv2.imwrite("debug_automatte.png", automatte_img)
124
+ # cv2.imwrite("debug_alpha.png", alpha)
125
+ # cv2.imwrite("debug_thresholded_alpha.png", thresholded_alpha)
126
+ # cv2.imwrite("debug_contracted_alpha.png", contracted_alpha)
127
+ # cv2.imwrite("debug_selection_mask.png", selection_mask)
128
+ # cv2.imwrite("debug_filtered_rgb.png", filtered_rgb)
129
  # import sys; sys.exit(0)
130
 
 
 
 
131
  # Apply the original contracted alpha (before inversion) to the filtered RGB image
132
  # Convert to RGBA
133
  expanded_rgba = cv2.cvtColor(filtered_rgb, cv2.COLOR_BGR2BGRA)
 
156
  expanded_pattern = os.path.join(expanded_base, "*", "*.png")
157
  expanded_files = glob.glob(expanded_pattern)
158
 
159
+ # Sort the expanded files to ensure consistent processing order
160
+ expanded_files.sort()
161
+
162
  for expanded_path in expanded_files:
163
  # Extract relative path from expanded base
164
  rel_path = os.path.relpath(expanded_path, expanded_base)