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)