python convert rgb to hsv

The documentation of colorsys explains that all colour space coordinates are floating point numbers between 0.0 and 1.0 – rescale your values accordingly to get the desired results:

>>> h, s, v = colorsys.rgb_to_hsv(144/255., 190/255., 255/255.)
>>> 360 * h, 100 * s, 100 * v
(215.13513513513513, 43.529411764705884, 100.0)

colorsys.hls_to_rgb(h, l, s)

Convert the color from HLS coordinates to RGB coordinates.

import Imge,colorsys    
LenaImage1 ='lena.png')
r,g,b = LenaImage1.split()
Hdat = []
Ldat = []
Sdat = []    
for rd,gn,bl in zip(r.getdata(),g.getdata(),b.getdata()):
    h,l,s = colorsys.rgb_to_hls(rd/255.,gn/255.,bl/255.)

newimg = Image.merge('RGB',(r,g,b))'lenaHSV.png')

Hue describes the shade of color and where that color it is found in the color spectrum. Red, yellow, and purple are words that describe hue.
Figure 5.3
S. The saturation describes how pure the hue is with respect to a white reference.
S. The saturation describes how pure the hue is with respect to a white reference.  Saturation refers to the dominance of hue in the color. On the outer edge of the hue wheel are the ‘pure’ hues. As you move into the center of the wheel, the hue we are using to describe the color dominates less and less. When you reach the center of the wheel, no hue dominates.
One of the dimensions is lightness-darkness. How light or dark a color is is referred to either as a colors lightness or value.

These colors directly on the central axis are considered desaturated. These desaturated colors constitute the  grayscale; running from white to black with all of the intermediate grays in between.

Saturation, therefore, is the dimension running from the outer edge of the hue wheel (fully saturated) to the center (fully desaturated), perpendicular to the value axis

A horizontal slice of the model shown in Figure 9  creates a disk of the hues running around the perimeter. The farther down the value axis, the more restricted the saturation range (the radius of the disk) is and, therefore, the smaller the disk.

Another way you can slice the HSV model solid is vertically. If you took a slice along the saturation axis at a red hue, it might look something like Figure 10:

Figure 10 – A saturation/value slice of a specific hue in the HSV model

This wedge shows all of the saturation and value variations on this particular red. At the top of the wedge, the lightest red runs from high saturation on the right to white on the left. As you move down the wedge, the reds get darker and the saturation range from right to left gets narrower. We can take this theoretical wedge and actually try and see how many saturation and value variations on this red you can make. It might look something like Figure 11:

Figure 11 – Example saturation and value variations on a single red hue

The goal in Figure 11 was to create even increments of saturation going right to left and even increments of value top to bottom. This judgment was made by your ‘eye’, not by some numeric readout from a color mixing tool. Because you are using your ‘eye’, no one’s wedge would exactly like anyone’s else’s. Notice that the end result in Figure 11 is not a perfect triangle. Though more color squares could have been made for the darker reds, you would not have been able tell the difference in color between them. Similarly, if you removed some of the squares in the lighter value range, you would have to have made bigger steps of saturation to get the full range that you can see.




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web