0

I'm converting RGB triplets to LAB in this way.

from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color

for p in range(0,h):
    for q in range(0,w):
        rgb_color = sRGBColor(img_arr[p][q][0],img_arr[p][q][1],img_arr[p][q][2])
        lab_color = convert_color(rgb_color, LabColor)

But this method is slow. Is there a way I can convert img_arr from RGB to LAB without loops? I want to use colormath only.

Harsh Wardhan
  • 2,110
  • 10
  • 36
  • 51
  • Not sure if you can do much better with or without loops in this case, as the conversion functions dominate the spent time. – Ilja Everilä Jun 03 '16 at 07:39
  • Even though you state that you want to use `colormath` only, have a look at http://stackoverflow.com/questions/13405956/convert-an-image-rgb-lab-with-python. Much much faster. – Ilja Everilä Jun 03 '16 at 07:45
  • I've seen this link before. – Harsh Wardhan Jun 03 '16 at 08:08
  • 2
    @HarshWardhan: Colormath is not vectorised, so you can't get much speed from it, is it a strong requirement or would an alternative Python library work for you? https://github.com/colour-science/colour should cover pretty much everything colormath does but in a vectorised way, thus order of magnitude faster. – Kel Solaar Jun 05 '16 at 05:25

0 Answers0