I'm trying to accomplish a basic image processing. Here is my algorithm :
Find n., n+1., n+2. pixel's RGB values in a row and create a new image from these values.
Here is my example code in python :
import glob
import ntpath
import time
from multiprocessing.pool import ThreadPool as Pool
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
images = glob.glob('model/*.png')
pool_size = 17
def worker(image_file):
try:
new_image = np.zeros((2400, 1280, 3), dtype=np.uint8)
image_name = ntpath.basename(image_file)
print(f'Processing [{image_name}]')
image = Image.open(image_file)
data = np.asarray(image)
for i in range(0, 2399):
for j in range(0, 1279):
pix_x = j * 3 + 1
red = data[i, pix_x - 1][0]
green = data[i, pix_x][1]
blue = data[i, pix_x + 1][2]
new_image[i, j] = [red, green, blue]
im = Image.fromarray(new_image)
im.save(f'export/{image_name}')
except:
print('error with item')
pool = Pool(pool_size)
for image_file in images:
pool.apply_async(worker, (image_file,))
pool.close()
pool.join()
My input and output images are in RGB format. My code is taking 5 second for every image. I'm open for any idea to optimization this task.
Here is example input and output images :
Input Image2 [ 3840 x 2400 ]
Output Image3 [ 1280 x 2400 ]
