-1

I have an RGB image that I want to convert to the HSV colorspace. The RGB values in the image array have a range of 0 to 255. However, almost all of the colorspace conversion functions out there require the data to have a range of 0 to 1.

Is there anyway to get around this (short of writing my own conversion function)? If not, what is the fastest way to change the data range from 0, 255 to 0, 1 (the array dimensions vary but are typically [1000, 1000, 3])

martineau
  • 119,623
  • 25
  • 170
  • 301
DeeWBee
  • 695
  • 4
  • 13
  • 38
  • @Kevin so if I have a [1000, 1000, 3] array called `img`, would I just do `img[:, :, :] / 255.0`? – DeeWBee Aug 03 '16 at 16:23
  • .. and then use [`colorsys`](https://docs.python.org/3.4/library/colorsys.html) – dhke Aug 03 '16 at 16:24
  • 1
    @DeeWBee, hard to say. I guess that depends on what type `img` is. You can't divide an ordinary list by a number, and the same is true for [array.array](https://docs.python.org/2/library/array.html)s. But maybe it would work on numpy arrays? I'm not sure, I've barely used that library. – Kevin Aug 03 '16 at 16:30
  • @Kevin no problem. Appreciate the help – DeeWBee Aug 03 '16 at 16:33
  • 1
    @DeeWBee Yes, if it's a numpy array then you can do `img[:, :, :] / 255.0` or just `img/255.0`, which does the same. – Torkel Bjørnson-Langen Aug 03 '16 at 16:34

1 Answers1

1

You can use preprocessing.MinMaxScaler() from scikit-learn.

Here is link for more information and examples.

Dataman
  • 3,457
  • 3
  • 19
  • 31