[Numpy-discussion] RGB <-> HSV in numpy?
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(). How do I run RGB <-> HSV conversion on the nd array? I'd like to keep SV values in the range of 0-1, and H in 0-360. Thank you. -- Best regards, He Shiming ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] RGB <-> HSV in numpy?
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 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] RGB <-> HSV in numpy?
On Sat, Aug 20, 2011 at 4:17 PM, David Warde-Farley wrote: > > 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 Thanks, I'll check it out. -- Best regards, He Shiming ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] RGB <-> HSV in numpy?
> On Sat, Aug 20, 2011 at 4:17 PM, David Warde-Farley > wrote: > > Thanks, I'll check it out. > > -- > Best regards, > He Shiming > Hi again. Project scikits.image appeared to be difficult to install under ubuntu. It complains about something related to OpenCV, and I didn't see any option to compile without it. I'm wondering if there are any simpler solutions, without using scikits.image or scipy, just numpy plus calculations. All I'm trying to do is to convert this algorithm: http://code.activestate.com/recipes/576919-python-rgb-and-hsv-conversion/ to numpy flavor. -- Best regards, He Shiming ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] RGB <-> HSV in numpy?
On Mon, Aug 22, 2011 at 5:39 AM, He Shiming wrote: > > On Sat, Aug 20, 2011 at 4:17 PM, David Warde-Farley > > wrote: > > > > Thanks, I'll check it out. > > > > -- > > Best regards, > > He Shiming > > > > Hi again. Project scikits.image appeared to be difficult to install > under ubuntu. It complains about something related to OpenCV, and I > didn't see any option to compile without it. I'm wondering if there > are any simpler solutions, without using scikits.image or scipy, just > numpy plus calculations. All I'm trying to do is to convert this > algorithm: > http://code.activestate.com/recipes/576919-python-rgb-and-hsv-conversion/ > to numpy flavor. > > You can use this file standalone without installing scikits.image: https://github.com/stefanv/scikits.image/blob/master/scikits/image/color/colorconv.py Ralf ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] RGB <-> HSV in numpy?
On Mon, Aug 22, 2011 at 2:21 PM, Ralf Gommers wrote: > > > You can use this file standalone without installing scikits.image: > https://github.com/stefanv/scikits.image/blob/master/scikits/image/color/colorconv.py > > Ralf > > > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > Thanks Ralf. I've managed to extract the conversion routines from this colorconv.py, and adapted it on RGBA sequence. -- Best regards, He Shiming ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion