I have a very simple method that converts an RGB image to HSL and adjusts the Hue. This works relatively quickly with small image files, but large image files require minutes to process. I am converting the imgdata
to a numpy array, but this does not seem to speed it up at all. Do I have to use numpy functions exclusively inside of the loop to speed this up? I can't find exactly where the bottleneck is inside of the loop as it is just fairly simple math calculations.
from colorsys import rgb_to_hls, hls_to_rgb
from numpy import array
def reload_img():
global img, sizew, sizeh, maxsize, imgdata
img = Image.open(IMAGE_SRC)
sizew, sizeh = img.size
maxsize = ((sizew/2)**2 + (sizeh/2)**2)**0.5
imgdata = list(img.getdata())
# Convert to numpy array
imgdata = array(imgdata)
IMAGE_SRC = "test.jpg"
reload_img()
# Adjust Hue
for i in range(0,len(imgdata)):
r,g,b = imgdata[i]
r /= 255.0
g /= 255.0
b /= 255.0
(h, l, s) = rgb_to_hls(r,g,b)
h = .50
imgdata[i] = hls2rgb((h,l,s))