File size: 869 Bytes
1f765c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from multiprocessing import Pool, cpu_count
from modules.enhance import enhancement_pipeline

def process_image_chunk(args):
    """
    Worker function to process a horizontal slice of the image.
    """
    chunk, config = args
    return enhancement_pipeline(chunk, config)

def parallel_enhancement(img, config):
    """
    Orchestrates parallel image processing using multiprocessing Pool.
    """
    cores = max(1, cpu_count() - 1)
    # Split image into horizontal chunks based on number of logical cores
    chunks = np.array_split(img, cores, axis=0)
    
    # Prepare arguments for each worker
    worker_args = [(chunk, config) for chunk in chunks]
    
    with Pool(processes=cores) as pool:
        processed_chunks = pool.map(process_image_chunk, worker_args)
        
    # Reassemble chunks
    return np.vstack(processed_chunks)