jebin2 commited on
Commit
1dde7c9
·
1 Parent(s): 5409a61

added remain panel

Browse files
comic_panel_extractor/llm_panel_extractor.py CHANGED
@@ -233,6 +233,11 @@ def extract_panel_via_llm(input_image_path, config=None, reset=True):
233
  all_processed_boxes = panel_extractor.pre_all_processed_boxes(accumulated_detected_boxes, original_width, original_height)
234
 
235
  all_path = [file for file in os.listdir(extractor_config.output_folder) if "_panel_" in file]
 
 
 
 
 
236
 
237
  print(f"Processing complete. Final result saved to: {extractor_config.output_folder}")
238
  print(f"Total panels detected: {len(all_path)}")
 
233
  all_processed_boxes = panel_extractor.pre_all_processed_boxes(accumulated_detected_boxes, original_width, original_height)
234
 
235
  all_path = [file for file in os.listdir(extractor_config.output_folder) if "_panel_" in file]
236
+ remain_boxes = utils.get_remaining_areas((original_width, original_height), all_processed_boxes)
237
+ if remain_boxes:
238
+ panel_extractor.crop_and_save_detected_panels(remain_boxes)
239
+ all_processed_boxes.extend(remain_boxes)
240
+ accumulated_detected_boxes.extend(remain_boxes)
241
 
242
  print(f"Processing complete. Final result saved to: {extractor_config.output_folder}")
243
  print(f"Total panels detected: {len(all_path)}")
comic_panel_extractor/utils.py CHANGED
@@ -412,3 +412,35 @@ def find_similar_remaining_regions(boxes, image_shape, debug_image_path, w_t=0.2
412
  cv2.imwrite(debug_image_path, debug_img)
413
  return similar_boxes
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  cv2.imwrite(debug_image_path, debug_img)
413
  return similar_boxes
414
 
415
+ def get_remaining_areas(image_size, boxes):
416
+ """
417
+ Given the image size and a list of bounding boxes, returns the remaining uncovered areas
418
+ as rectangles.
419
+
420
+ Args:
421
+ image_size: (width, height) of the image.
422
+ boxes: List of (x1, y1, x2, y2) rectangles.
423
+
424
+ Returns:
425
+ List of rectangles representing the remaining uncovered areas.
426
+ """
427
+ width, height = image_size
428
+ # Create a binary mask of the image (0 = uncovered, 255 = covered)
429
+ mask = np.zeros((height, width), dtype=np.uint8)
430
+
431
+ # Mark the covered boxes
432
+ for x1, y1, x2, y2 in boxes:
433
+ mask[y1:y2, x1:x2] = 255
434
+
435
+ # Invert mask to get the remaining area
436
+ remaining_mask = cv2.bitwise_not(mask)
437
+
438
+ # Find contours in the remaining area
439
+ contours, _ = cv2.findContours(remaining_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
440
+
441
+ remaining_boxes = []
442
+ for contour in contours:
443
+ x, y, w, h = cv2.boundingRect(contour)
444
+ remaining_boxes.append((x, y, x + w, y + h))
445
+
446
+ return remaining_boxes