Spaces:
Running
Running
File size: 2,789 Bytes
97aa4e5 d5daafd 97aa4e5 d5daafd df846c6 d5daafd 953dc3a d5daafd 953dc3a d5daafd c01fc99 14beaec df846c6 c01fc99 97aa4e5 c01fc99 97aa4e5 20bec6b 97aa4e5 dac564b 20bec6b 0e59abf 953dc3a 0e59abf d5daafd 953dc3a d5daafd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# from .text_detector import TextDetector
from .config import Config
from .image_processor import ImageProcessor
from .panel_extractor import PanelData
from .panel_extractor import PanelExtractor
from .panel_segmentation import main as basic_panel_segmentation
from typing import List, Tuple
from pathlib import Path
import numpy as np
from .border_panel_extractor import BorderPanelExtractor
import shutil
class ComicPanelExtractor:
"""Main class that orchestrates the comic panel extraction process."""
def __init__(self, config: Config, reset: bool = True):
self.config = config
if reset:
if Path(self.config.output_folder).exists():
shutil.rmtree(self.config.output_folder)
Path(self.config.output_folder).mkdir(exist_ok=True)
self.image_processor = ImageProcessor(self.config)
self.panel_extractor = PanelExtractor(self.config)
def extract_panels_from_comic(self) -> Tuple[List[np.ndarray], List[PanelData]]:
"""Complete pipeline to extract panels from a comic image."""
print(f"Starting panel extraction for: {self.config.input_path}")
processed_image_path = self.config.input_path
processed_image_path = BorderPanelExtractor(self.config).main(processed_image_path)
self.config.black_overlay_input_path = processed_image_path
_, _, processed_image_path = self.image_processor.preprocess_image(processed_image_path)
processed_image_path = self.image_processor.thin_image_borders(processed_image_path)
processed_image_path = self.image_processor.remove_dangling_lines(processed_image_path)
processed_image_path = self.image_processor.remove_diagonal_only_cells(processed_image_path)
processed_image_path = self.image_processor.remove_small_continuity_components(processed_image_path)
processed_image_path = self.image_processor.thick_black(processed_image_path)
processed_image_path = self.image_processor.remove_small_regions(processed_image_path)
processed_image_path = self.image_processor.remove_diagonal_lines(processed_image_path)
processed_image_path = self.image_processor.remove_small_regions(processed_image_path)
processed_image_path = self.image_processor.connect_horizontal_vertical_gaps(processed_image_path)
processed_image_path = self.image_processor.thin_image_borders(processed_image_path)
panel_images, panel_data, all_panel_path = self.panel_extractor.extract_panels(
processed_image_path
)
return panel_images, panel_data, all_panel_path
def cleanup(self):
"""Clean up temporary files if needed."""
# Add cleanup logic here if needed
pass |