jebin2 commited on
Commit
8b56694
·
1 Parent(s): 0622274

Remove Inner Sketch

Browse files
comic_panel_extractor/image_processor.py CHANGED
@@ -73,7 +73,40 @@ class ImageProcessor:
73
  # Save result
74
  return inverted, black_pixels > white_pixels
75
 
76
- def thin_image_borders(self, processed_image_path: str, output_filename: str = "5_thin_border.jpg") -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  """
78
  Clean dilated image by thinning thick borders and removing hanging clusters.
79
  """
 
73
  # Save result
74
  return inverted, black_pixels > white_pixels
75
 
76
+ def remove_inner_sketch(self, input_path, output_filename="5_remove_inner_sketch.jpg", min_area_ratio=0):
77
+ img = cv2.imread(input_path, cv2.IMREAD_GRAYSCALE)
78
+ height, width = img.shape
79
+
80
+ # Threshold image to binary
81
+ _, binary = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)
82
+
83
+ # Find all contours
84
+ contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
85
+
86
+ # Create mask for large contours (likely panel borders)
87
+ mask = np.zeros_like(binary)
88
+ for cnt in contours:
89
+ area = cv2.contourArea(cnt)
90
+ if area >= (height * width * min_area_ratio):
91
+ cv2.drawContours(mask, [cnt], -1, 255, thickness=cv2.FILLED)
92
+
93
+ # Apply mask to original image (keeps only large borders)
94
+ cleaned = cv2.bitwise_and(binary, binary, mask=mask)
95
+
96
+ # Optional: Apply morphological opening to clean tiny sketch lines
97
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
98
+ cleaned = cv2.morphologyEx(cleaned, cv2.MORPH_OPEN, kernel)
99
+
100
+ # Invert back if needed
101
+ cleaned = cv2.bitwise_not(cleaned)
102
+
103
+ # Save
104
+ output_path = f'{self.config.output_folder}/{output_filename}'
105
+ cv2.imwrite(output_path, cleaned)
106
+ print(f"✅ Remove Inner Sketch image saved to: {output_path}")
107
+ return str(output_path)
108
+
109
+ def thin_image_borders(self, processed_image_path: str, output_filename: str = "6_thin_border.jpg") -> str:
110
  """
111
  Clean dilated image by thinning thick borders and removing hanging clusters.
112
  """
comic_panel_extractor/main.py CHANGED
@@ -34,13 +34,16 @@ class ComicPanelExtractor:
34
  # Step 2: Preprocess image
35
  _, _, processed_image_path = self.image_processor.preprocess_image(masked_image_path)
36
 
37
- # Step 3: Thin border line
 
 
 
38
  processed_image_path = self.image_processor.thin_image_borders(processed_image_path)
39
 
40
  # Step 3: Clean dilated image
41
  # processed_image_path = self.image_processor.clean_dilated_image(processed_image_path)
42
 
43
- # Step 4: Extract panels
44
  panel_images, panel_data, all_panel_path = self.panel_extractor.extract_panels(
45
  processed_image_path
46
  )
 
34
  # Step 2: Preprocess image
35
  _, _, processed_image_path = self.image_processor.preprocess_image(masked_image_path)
36
 
37
+ # Step 3: Remove Inner Sketch
38
+ processed_image_path = self.image_processor.remove_inner_sketch(processed_image_path)
39
+
40
+ # Step 4: Thin border line
41
  processed_image_path = self.image_processor.thin_image_borders(processed_image_path)
42
 
43
  # Step 3: Clean dilated image
44
  # processed_image_path = self.image_processor.clean_dilated_image(processed_image_path)
45
 
46
+ # Step 5: Extract panels
47
  panel_images, panel_data, all_panel_path = self.panel_extractor.extract_panels(
48
  processed_image_path
49
  )