File size: 736 Bytes
ed72314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import tempfile
from PIL import Image, ImageEnhance
from typing import List

from config import CONTRAST_ENHANCEMENT, SHARPNESS_ENHANCEMENT


def preprocess_images(image_paths: List[str]) -> List[str]:
    cleaned_paths = []
    
    for i, path in enumerate(image_paths):
        img = Image.open(path).convert("RGB")
        
        enhancer = ImageEnhance.Contrast(img)
        img = enhancer.enhance(CONTRAST_ENHANCEMENT)
        
        enhancer = ImageEnhance.Sharpness(img)
        img = enhancer.enhance(SHARPNESS_ENHANCEMENT)
        
        save_path = os.path.join(tempfile.gettempdir(), f"input_refined_{i}.png")
        img.save(save_path)
        cleaned_paths.append(save_path)
    
    return cleaned_paths