Ask Question
3 February, 14:05

How to write a program converting RGB to CMYK in python

+4
Answers (1)
  1. 3 February, 17:28
    0
    rgb_scale = 255

    cmyk_scale = 100

    def rgb_to_cmyk (r, g, b):

    if (r = = 0) and (g = = 0) and (b = = 0):

    return 0, 0, 0, cmyk_scale

    # rgb [0,255] - > cmy [0,1]

    c = 1 - r / float (rgb_scale)

    m = 1 - g / float (rgb_scale)

    y = 1 - b / float (rgb_scale)

    min_cmy = min (c, m, y)

    c = (c - min_cmy)

    m = (m - min_cmy)

    y = (y - min_cmy)

    k = min_cmy

    return c*cmyk_scale, m*cmyk_scale, y*cmyk_scale, k*cmyk_scale

    def cmyk_to_rgb (c, m, y, k):

    r = rgb_scale * (1.0 - (c+k) / float (cmyk_scale))

    g = rgb_scale * (1.0 - (m+k) / float (cmyk_scale))

    b = rgb_scale * (1.0 - (y+k) / float (cmyk_scale))

    return r, g, b
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “How to write a program converting RGB to CMYK in python ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers