- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Conversions between color systems using Python (colorsys)
The RGB color model, named so because of the initials of the three additive primary colors, is an additive color model in which red, green and blue light are added to reproduce various colors.
The RGB color model is used in representation and display of images in electronic systems, such as televisions and computers. It is based on human perception of colors. Other alternative representations of color model are:
YIQ: Luminance, Chrominance (used by composite video signals)
HLS: Hue, Luminance, Saturation
HSV: Hue, Saturation, Value
The colorsys module defines functions for conversion of color values between RGB color model and three other coordinate systems. In the YIQ model, the Y value is between 0 and 1, but the I and Q values may be positive or negative. In RGB, HLS and HSV model, the values are all between 0 and 1.
This module provides two functions for each color system to RGB and vice versa.
|rgb_to_yiq()||Convert RGB to YIQ|
|yiq_to_rgb()||Convert YIQ to RGB|
|rgb_to_hls()||Convert RGB to HLS|
|hls_to_rgb()||Convert HLS to RGB|
|rgb_to_hsv()||Convert RGB to HSV|
|hsv_to_rgb()||Convert HSV to RGB|
>>> import colorsys >>> r,g,b=1, 0.753, 0.80 >>> colorsys.rgb_to_hls(r,g,b) (0.9682860998650472, 0.8765000000000001, 1.0) >>> colorsys.rgb_to_hsv(r,g,b) (0.9682860998650472, 0.247, 1) >>> colorsys.rgb_to_yiq(r,g,b) (0.83227, 0.1328331, 0.06727970000000007)
- colorsys module in Python
- Java Conversions and Promotions
- Color game using Tkinter in Python
- Difference between AC and DC Transmission Systems
- Write a C program for time conversions using if and elseif statements
- What are explicit type conversions in C#?
- What are implicit type conversions in C#?
- Difference between FAT32, exFAT, and NTFS File Systems.
- State the difference between file systems and DBMS?
- Signals and Systems: Classification of Systems
- Difference between 32-bit and 64-bit operating systems
- Signals and Systems – Relation between Convolution and Correlation
- Program to fill with color using floodfill operation in Python
- Program to determine color of a chessboard square using Python
- Setting Text Color using CSS