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.
I'm taking first pixel's red value,second pixel's green value and third pixel's blue value and create pixel. This operation continue for every row in image.
Here is my example code in python :
import glob
import ntpath
import numpy
from PIL import Image
images = glob.glob('balls/*.png')
data_compressed = numpy.zeros((540, 2560, 3), dtype=numpy.uint8)
for image_file in images:
print(f'Processing [{image_file}]')
image = Image.open(image_file)
data = numpy.loadasarray(image)
for i in range(0, 2559):
for j in range(0, 539):
pix_x = j * 3 + 1
red = data[pix_x - 1, i][0]
green = data[pix_x, i][1]
blue = data[pix_x + 1, i][2]
data_compressed[j, i] = [red, green, blue]
im = Image.fromarray(data_compressed)
image_name = ntpath.basename(image_file)
im.save(f'export/{image_name}')
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. I can use c++ or any other languages if necessary.


