Color Format Converter Project

Color Format Converter Project

Programming Project in Python

The RGB color model is an additive model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. It is the most common color model used in electronic displays, such as televisions, computer monitors, and digital cameras. RGB defines the level of red (R), green (G), and blue (B) through integers from 0 to 255. On the other hand, the CMYK format defines the amount of cyan (C), magenta (M), yellow (Y), and black (K) on a real scale from 0 to 1.

The mathematical formulas for converting from RGB to an equivalent CMYK in this programming project in Python are:

  • White = maximum of {red/255, green/255, blue/255}
  • Cyan = (white – red/255)/white
  • Magenta = (white – green/255)/white
  • Yellow = (white – blue/255)/white
  • Black = 1 -white

The RGB color table is the following:

Black: (0,0,0)
White (255,255,255)
Red (255,0,0)
Lime (0,255,0)
Blue (0,0,255)
Yellow (255,255,0)
Cyan (0,255,255)
Magenta 255,0,255)
Green (0,128,0)

Write a Python program that first displays the RGB color table, prompts the user to select  one colour and prints out the equivalent CMYK parameters.

Expected output

RGB Color Table:
Color      Red        Green     
Black      0          0          0         
White      255        255        255       
Red        255        0          0         
Lime       0          255        0         
Blue       0          0          255       
Yellow     255        255        0         
Cyan       0          255        255       
Magenta    255        0          255       
Green      0          128        0         
Enter the name of the color: Blue
CMYK parameters for Blue: Cyan=1.000, Magenta=1.000, Yellow=0.000, Black=0.000

Source Code


# Step 1: Create the RGB color table
rgb_color_table = {
    "Black": (0, 0, 0),
    "White": (255, 255, 255),
    "Red": (255, 0, 0),
    "Lime": (0, 255, 0),
    "Blue": (0, 0, 255),
    "Yellow": (255, 255, 0),
    "Cyan": (0, 255, 255),
    "Magenta": (255, 0, 255),
    "Green": (0, 128, 0)
}

# Step 2: Display the RGB color table as a table
print("RGB Color Table:")
print("{:<10} {:<10} {:<10}".format('Color', 'Red', 'Green', 'Blue'))
for color, rgb in rgb_color_table.items():
    print("{:<10} {:<10} {:<10} {:<10}".format(color, rgb[0], rgb[1], rgb[2]))

# Step 3: Prompt the user for color selection
selected_color = input("Enter the name of the color: ")

# Step 4: Convert the selected RGB value to CMYK
red, green, blue = rgb_color_table[selected_color]
white = max(red/255, green/255, blue/255)
cyan = (white - red/255) / white
magenta = (white - green/255) / white
yellow = (white - blue/255) / white
black = 1 - white

# Step 5: Print the CMYK parameters
print(f"CMYK parameters for {selected_color}: Cyan={cyan:.3f}, Magenta={magenta:.3f}, Yellow={yellow:.3f}, Black={black:.3f}")

To keep practicing Python, visit Practity’s real projects.

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart