I am making an online image editor, and I am implementing a Hue/Sat/Lum editor. Here is my function to change the image with the given values.
def make_edit(pixels, hue, sat, lum):
shape = pixels.shape
new = np.empty(shape)
print(time.time())
for row_count, row in enumerate(pixels):
for pixel_count, p in enumerate(row):
new_hue = p[0] + hue
if new_hue < 0:
new_hue += 255
elif new_hue > 255:
new_hue -= 255
new_sat = p[1] + sat
if new_sat < 0:
new_sat += 255
elif new_sat > 255:
new_sat -= 255
new_lum = p[2] + lum
if new_lum < 0:
new_lum = 0
elif new_lum > 255:
new_lum = 255
new[row_count, pixel_count] = np.array([new_hue, new_sat, new_lum])
print(time.time())
return new
The function takes a numpy array in shape (height, width, 3). I am doing it pixel by pixel, then adding the hue, sat and lum value to each pixel. It takes 13 seconds (on a (648, 1152, 3) shaped array) however, obviously too long. Is there a numpy function that could offset all values by the amount I give it. p.s. the function doesn't work yet, hue seems to, but sat and lum don't give the correct images.