File size: 1,224 Bytes
ad8cacf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Background removal handling functionality.

"""

import os
from utils.background_removal import (
    remove_background_simple,
    remove_background_advanced
)

def handle_background_removal(image_paths, output_dir, method):
    """

    Handle background removal process.

    

    Args:

        image_paths (list): List of paths to input images

        output_dir (str): Directory for output

        method (str): Background removal method ('simple' or 'advanced')

        

    Returns:

        list: Paths to processed images

    """
    bg_removed_dir = os.path.join(output_dir, "bg_removed")
    os.makedirs(bg_removed_dir, exist_ok=True)
    
    bg_removed_paths = []
    for img_path in image_paths:
        filename = os.path.basename(img_path)
        output_path = os.path.join(bg_removed_dir, filename)
        
        if method == "simple":
            processed_path = remove_background_simple(img_path, output_path)
        else:
            processed_path = remove_background_advanced(img_path, output_path)
        
        if processed_path:
            bg_removed_paths.append(processed_path)
    
    return bg_removed_paths if bg_removed_paths else image_paths