Request for help with Image color space conversion

Robert Kern robert.kern at gmail.com
Sat Jan 5 00:48:58 CET 2008


ttest wrote:
> Hello,
> 
> I'm working on an image processing project using the Python Imaging
> Library along with numpy.  Right now, I'm trying to build a speedy
> script for converting whole images between the RGB and the HSV (a.k.a.
> HSB) color spaces.  Unfortunately, the code I've made so far runs
> dreadfully slow with even moderate-sized images.
> 
> I'm under the impression that the crux of the problem is the fact that
> PIL's point method operates on only one band at a time, and to do a
> proper color space conversion, you need information about all three
> bands in a particular problem.  This has forced me to do an awkward
> work-around where the image data is loaded into a numpy array
> (1600x1200x3), and a dinky for-loop run runs through the array picking
> up RGB values, converting to HSV, and dumping the results back into
> another array.
> 
> How can I make this more efficient?

Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
scalars. Only minor modifications are necessary.

-- 
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




More information about the Python-list mailing list