2

I have been trying to convert a large list of rgb arrays to hsv arrays in the following way and it got killed every time due to memory, could anyone kindly suggest a better way to do it? Preferably the result should be a large list of hsv arrays but if that's not the way to go, I'm good with any other forms of storage to work with.

Here are my current codes:

os.chdir("/mnt/saswork/sh2264/vision/code")
X_train_matched = np.load("X_train_scores.npy")

R = [r[0] for r in X_train_matched]
G = [g[1] for g in X_train_matched]
B = [b[2] for b in X_train_matched]

import colorsys

#hsv = [[[colorsys.rgb_to_hsv(x,y,z) for x,y,z in zip(a,b,c)]for a,b,c in zip(d,e,f)] for d,e,f in zip(R,G,B)]
# this is too memory intense
hsv = []
for image in X_train_matched:
    hsv.append([colorsys.rgb_to_hsv(x,y,z) for x,y,z in zip(a,b,c)] for a,b,c in zip(image[0],image[1],image[2])])

Thanks a million!

hpaulj
  • 221,503
  • 14
  • 230
  • 353
shenglih
  • 879
  • 2
  • 8
  • 18
  • 1
    You could consider using `opencv`: https://stackoverflow.com/questions/42198408/python-opencv-convert-pixel-from-bgr-to-hsv – sshashank124 Feb 20 '18 at 13:52
  • What's the shape (and dtype) of `X_train_matched`? What about the result of `colorsys.rgb_to_hsv(x,y,z)` compared to its inputs? – hpaulj Feb 20 '18 at 17:15
  • @hpaulj: according to the [`colorsys` docs](https://docs.python.org/3.6/library/colorsys.html) all of the functions in the module take three floats and return three float tuples. – Steven Rumbalski Feb 20 '18 at 19:16
  • @hpaulj, `X_train_matched.shape = (219300,3,200,200)`, thanks! – shenglih Feb 20 '18 at 19:57

0 Answers0