The documentation of
colorsys explains that all colour space coordinates are floating point numbers between
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 = Image.open('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.) Hdat.append(int(h*255.)) Ldat.append(int(l*255.)) Sdat.append(int(s*255.)) r.putdata(Hdat) g.putdata(Ldat) b.putdata(Sdat) newimg = Image.merge('RGB',(r,g,b)) newimg.save('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.
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.
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.