[Image-SIG] HSL adjustment, and others

Bob Klimek klimek at grc.nasa.gov
Mon Apr 11 21:27:52 CEST 2005


Ray Pasco wrote:

> I've been playing around with just this. This program converts to/from 
> several different colorspaces and changes the alternate colorspace's 
> "ramp" slope and offset. The program only does linear adjustments.
>
> I'd appreciate any comments/suggestions you may have.

Hi Ray,

I've taken a quick look at your rgb-hsl (and hsl-rgb) and rgb-hsv (and 
hsv-rgb) transformations and from the few tests I've run, both 
algorithms seem to be working quite well. And both successfully convert 
to and from. I don't see any difference really, although I don't have 
the time to do a thorough comparison.

My interest is only in hue so I've looked at that component only. I have 
a test image of a type of "rainbow" in which the hue changes from 1.0 
down to 0.0 in a linear fashion as the image is scanned from left to 
right. I use an old algorithm which produces a linear relationship 
between hue and posistion in this image. To my surprise both of these 
algorithms also produce a linear relationship.

BTW, the algorithm that I use (see below) come from Computer Graphics 
Quarterly Report SIGGRAPH-ACM, vol 13, Number 3, Aug. 1979. The hue 
range is from 0 to 2pi. One interesting thing we've noticed is that some 
hue values repeat them selves. That is an 8-bit deep RGB image has 16 
million rgb combinations but our hue algorithm produces only a few 
thousand unique values, not 16 million. All others are repeated hue values.

Anyway, it would be very nice to have a fast image-wide HSI 
transformation done in C with the output as a float array. Maybe some day...

    def calcHue(self, r, g, b):
        rf = float(r)
        gf = float(g)
        bf = float(b)
        rf = rf/255.0
        gf = gf/255.0
        bf = bf/255.0
        inten = (rf+gf+bf)/3.0
        if(not((r==b) and (r==g))):
            min = rf
            if(min>gf): min = gf
            if(min>bf): min = bf
            sat=1.0-(min/inten)
            t1 = rf-gf
            t2 = rf-bf
            t3 = gf-bf
            t4 = math.sqrt((t1*t1)+(t2*t3))
            t5 = (t1+t2)/2.0
            t5 = t5/t4
            hue = math.acos(t5)
            if(gf<bf): hue=2.0*math.pi-hue
        else:
            hue=-1000.0
            sat=-1.0
        return (hue, sat)

Bob



More information about the Image-SIG mailing list