jebin2 commited on
Commit
d00f531
·
1 Parent(s): 359e487

removed mostly black

Browse files
comic_panel_extractor/panel_extractor.py CHANGED
@@ -230,6 +230,18 @@ class PanelExtractor:
230
  for idx, (x1, y1, x2, y2) in enumerate(panels, 1):
231
  # Extract panel image
232
  panel_img = original[y1:y2, x1:x2]
 
 
 
 
 
 
 
 
 
 
 
 
233
  panel_images.append(panel_img)
234
 
235
  # Create panel data
@@ -250,5 +262,5 @@ class PanelExtractor:
250
  visual_path = f'{self.config.output_folder}/panels_visualization.jpg'
251
  cv2.imwrite(str(visual_path), visual_output)
252
 
253
- print(f"✅ Extracted {len(panels)} panels after filtering.")
254
  return panel_images, panel_data, all_panel_path
 
230
  for idx, (x1, y1, x2, y2) in enumerate(panels, 1):
231
  # Extract panel image
232
  panel_img = original[y1:y2, x1:x2]
233
+
234
+ # Check if more than 90% pixels are black
235
+ gray = cv2.cvtColor(panel_img, cv2.COLOR_BGR2GRAY)
236
+ black_pixels = np.sum(gray < 30) # pixel intensity <30 considered black
237
+ total_pixels = gray.size
238
+ black_ratio = black_pixels / total_pixels
239
+
240
+ if black_ratio > 0.9:
241
+ print(f"⚠️ Skipping panel #{idx} — {round(black_ratio * 100, 2)}% black")
242
+ continue
243
+
244
+ # Add to results
245
  panel_images.append(panel_img)
246
 
247
  # Create panel data
 
262
  visual_path = f'{self.config.output_folder}/panels_visualization.jpg'
263
  cv2.imwrite(str(visual_path), visual_output)
264
 
265
+ print(f"✅ Extracted {len(panel_images)} panels after filtering.")
266
  return panel_images, panel_data, all_panel_path