CMYK to RGB Conversion Algorithm

CMYK-ColoursCMYK and RGB are two different colour models. The CMYK model is used in the publishing/printing industry as it is based on the four basic colours used for printing colour images on white paper. The four colours of the CMYK model are Cyan, Magenta, Yellow and Black. The CMYK colours are subtractive. This means the colours get darker as you blend them together. This is what happens when you print a colour image on paper as the more ink/pigments you add, the darker the colour gets.

The RGB model on the other hand is base don the opposite effect. Using the RGB model, the colours get brighter as you increase their Red, Green or Blue values. RGB colours are used to represent colours on a computer screen and are hence used for light emission, not pigments. The colours grow brighter as you blend them or increase their intensity.

CMYK values are given either as percentages or values between 0 and 1 (e.g. 50% = 0.5), whereas RGB values are given using an integer value between 0 and 255.

Colour Colour Name (R,G,B) (C,M,Y,K)
Cyan (0,255,255) (100%,0%,0%,0%)
Magenta (255,0,255) (0%,100%,0%,0%)
Yellow (255,255,0) (0%,0%,100%,0%)
Black (0,0,0) (0%,0%,0%,100%)
Red (255,0,0) (0%,100%,100%,0%)
Green (0,255,0) (100%,0%,100%,0%)
Blue (0,0,255) (100%,100%,0%,0%)
White (255,255,255) (0%,0%,0%,0%)
Turquoise (48,213,200) (77%,0%,6%,16%)
Metallic Gold (212,175,55) (0%,17.45%,74.06%,16.86%)

It his possible to convert RGB code into CMYK code and vice versa using the formulas provided below.
rgb-to-cmyk

CMYK to RGB Conversion Formulas


CMYK-to-RGB-Conversion-Formulas

RGB to CMYK Conversion Formulas


RGB-to-CMYK-Conversion-Formulas

Programming Task


Using a programming language of your choice, create a computer program that:

  1. Asks the user to choose between two options:
    • RGB to CMYK conversion
    • CMYK to RGB conversion
  2. Retrieve the RGB or CMYK values based on the option selected
  3. Apply the conversion formulas to calculate the matching CMYK or RGB values
  4. Output the resulting CMYK or RGB values

Python Code


We have started the code for you, though you still need to complete the main two functions: RGB_to_CMYK() and CMYK_to_RGB()

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 9

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!