[Numpy-discussion] RGB <-> HSV in numpy?

David Warde-Farley wardefar at iro.umontreal.ca
Sat Aug 20 04:17:26 EDT 2011


On 2011-08-20, at 4:01 AM, He Shiming wrote:

> Hi,
> 
> I'm wondering how to do RGB <-> HSV conversion in numpy. I found a
> couple solutions through stackoverflow, but somehow they can't be used
> in my array format. I understand the concept of conversion, but I'm
> not that familiar with numpy.
> 
> My source buffer format is 'RGBA' sequence. I can take it into numpy
> via: numpy.fromstring(data, 'B').astype('I'). So that nd[0::4] becomes
> the array for the red channel. After color manipulation, I'll convert
> it back by nd.astype('B').tostring().


There are functions for this available in scikits.image:

http://stefanv.github.com/scikits.image/api/scikits.image.color.html

Although you may need to reshape it with reshape(arr, (width, height, 4)) or something similar first.

David


More information about the NumPy-Discussion mailing list