title: How to convert a rgb image into a cmyk?
body: <p>I want to convert a RGB image into CMYK. This is my code; the first problem is when I divide each pixel by 255, the value closes to zero, so the resulting image is approximately black! The second problem is that I don't know how to convert the one-channel resultant image to 4 channels. Of course, I'm not sure the made CMYK in the following code is correct. Thank you for your attention</p>
  <hr />
  <p><a href="https://i.stack.imgur.com/WF4Ut.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WF4Ut.jpg" alt="CMYK formula" /></a>
  <a href="https://i.stack.imgur.com/mr9TR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mr9TR.jpg" alt="Dr.Trump!" /></a></p>
  <pre><code>import cv2
  import numpy as np
  import time
  
  img = cv2.imread('image/dr_trump.jpg')
  
  B = img[:, :, 0]
  G = img[:, :, 1]
  R = img[:, :, 2]
  
  B_ = np.copy(B) 
  G_ = np.copy(G)
  R_ = np.copy(R)
  
  K = np.zeros_like(B) 
  C = np.zeros_like(B) 
  M = np.zeros_like(B) 
  Y = np.zeros_like(B) 
  
  ts = time.time()
  
  for i in range(B.shape[0]):
      for j in range(B.shape[1]):
          B_[i, j] = B[i, j]/255
          G_[i, j] = G[i, j]/255
          R_[i, j] = R[i, j]/255
  
          K[i, j] = 1 - max(B_[i, j], G_[i, j], R_[i, j])
          if (B_[i, j] == 0) and (G_[i, j] == 0) and (R_[i, j] == 0):
          # black
                C[i, j] = 0
                M[i, j] = 0  
                Y[i, j] = 0
          else:
          
              C[i, j] = (1 - R_[i, j] - K[i, j])/float((1 - K[i, j]))
              M[i, j] = (1 - G_[i, j] - K[i, j])/float((1 - K[i, j]))
              Y[i, j] = (1 - B_[i, j] - K[i, j])/float((1 - K[i, j]))
  
  
  CMYK = C + M + Y + K 
          
  t = (time.time() -ts)
  print(&quot;Loop: {:} ms&quot;.format(t*1000))
  
  
  cv2.imshow('CMYK by loop',CMYK)
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>