rgb_to_hsv in scipy.misc ? (was: [Numpy-discussion] Optimizing speed for large-array inter-element algorithms (specifically, color space conversion))

Hello, Would it be possible to include the following rgb to hsv conversion code in scipy (probably in misc along with misc.imread, etc.) ? What do you think? Thanks in advance. Best regards, -- Nicolas Pinto Ph.D. Candidate, Brain & Computer Sciences Massachusetts Institute of Technology, USA http://web.mit.edu/pinto # ------------------------------------------------------------------------------ import numpy as np def rgb_to_hsv_arr(arr): """ fast rgb_to_hsv using numpy array """ # adapted from Arnar Flatberg # http://www.mail-archive.com/numpy-discussion@scipy.org/msg06147.html # it now handles NaN properly and mimics colorsys.rgb_to_hsv output arr = arr/255. out = np.empty_like(arr) arr_max = arr.max(-1) delta = arr.ptp(-1) s = delta / arr_max s[delta==0] = 0 # red is max idx = (arr[:,:,0] == arr_max) out[idx, 0] = (arr[idx, 1] - arr[idx, 2]) / delta[idx] # green is max idx = (arr[:,:,1] == arr_max) out[idx, 0] = 2. + (arr[idx, 2] - arr[idx, 0] ) / delta[idx] # blue is max idx = (arr[:,:,2] == arr_max) out[idx, 0] = 4. + (arr[idx, 0] - arr[idx, 1] ) / delta[idx] out[:,:,0] = (out[:,:,0]/6.0) % 1.0 out[:,:,1] = s out[:,:,2] = arr_max # rescale back to [0, 255] out *= 255. # remove NaN out[np.isnan(out)] = 0 return out

Hi Nicolas 2009/2/18 Nicolas Pinto <pinto@mit.edu>:
Would it be possible to include the following rgb to hsv conversion code in scipy (probably in misc along with misc.imread, etc.) ?
I think SciPy could do with some more image processing algorithms. Would anyone mind if we added this sort of thing to the ndimage namespace? I'd also like to make available `imread` in that module. If there aren't any objections, I'd gladly help integrate the color conversion code. Regards Stéfan

+1 on rgb_to_hsv making it into SciPy. I needed it recently for some research code I'm working on. +1 on imread. Stefan, do you have any thoughts on its interface? I'm an advocate for making it as similar to MATLAB's interface as possible to make it easier for people to switch from MATLAB to Python. 2009/2/18 Stéfan van der Walt <stefan@sun.ac.za>:
Hi Nicolas
2009/2/18 Nicolas Pinto <pinto@mit.edu>:
Would it be possible to include the following rgb to hsv conversion code in scipy (probably in misc along with misc.imread, etc.) ?
I think SciPy could do with some more image processing algorithms. Would anyone mind if we added this sort of thing to the ndimage namespace? I'd also like to make available `imread` in that module.
If there aren't any objections, I'd gladly help integrate the color conversion code.
Regards Stéfan _______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-dev
-- ----------------------------------------------------- Damian Eads Ph.D. Candidate Jack Baskin School of Engineering, UCSC E2-489 1156 High Street Machine Learning Lab Santa Cruz, CA 95064 http://www.soe.ucsc.edu/~eads

Hi Damian 2009/7/7 Damian Eads <eads@soe.ucsc.edu>:
+1 on rgb_to_hsv making it into SciPy. I needed it recently for some research code I'm working on.
I've also needed that code recently, so I'd be glad to include it.
+1 on imread. Stefan, do you have any thoughts on its interface? I'm an advocate for making it as similar to MATLAB's interface as possible to make it easier for people to switch from MATLAB to Python.
It's already in :-) I'm open to any recommendations on the API. Cheers Stéfan

2009/7/7 Stéfan van der Walt <stefan@sun.ac.za>:
Hi Damian
2009/7/7 Damian Eads <eads@soe.ucsc.edu>:
+1 on rgb_to_hsv making it into SciPy. I needed it recently for some research code I'm working on.
I've also needed that code recently, so I'd be glad to include it.
+1 on imread. Stefan, do you have any thoughts on its interface? I'm an advocate for making it as similar to MATLAB's interface as possible to make it easier for people to switch from MATLAB to Python.
It's already in :-) I'm open to any recommendations on the API.
http://svn.scipy.org/svn/scipy/branches/sandbox/scipy/sandbox/image/color.py -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

Hi Stefan, 2009/7/7 Stéfan van der Walt <stefan@sun.ac.za>:
Hi Damian
2009/7/7 Damian Eads <eads@soe.ucsc.edu>:
+1 on rgb_to_hsv making it into SciPy. I needed it recently for some research code I'm working on.
I've also needed that code recently, so I'd be glad to include it.
I used the code in this message, http://www.mail-archive.com/numpy-discussion@scipy.org/msg15642.html . I don't know if it's correct or not.
+1 on imread. Stefan, do you have any thoughts on its interface? I'm an advocate for making it as similar to MATLAB's interface as possible to make it easier for people to switch from MATLAB to Python.
It's already in :-) I'm open to any recommendations on the API.
Two other arguments in the imread function would be helpful, roi and band. 'roi' is a 2 or 3 element tuple of coordinates to read, which is useful when reading from a very large image. Thanks! Damian
Cheers Stéfan _______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
-- ----------------------------------------------------- Damian Eads Ph.D. Candidate Jack Baskin School of Engineering, UCSC E2-489 1156 High Street Machine Learning Lab Santa Cruz, CA 95064 http://www.soe.ucsc.edu/~eads
participants (4)
-
Damian Eads
-
Nicolas Pinto
-
Robert Kern
-
Stéfan van der Walt