title: How to Plot Image Log-Chromaticity Plot in Python OpenCV
body: <p>I am trying to create a 2D log chromaticity plot in python with OpenCV. The same question was asked here</p>
  
  <p><a href="https://stackoverflow.com/questions/23282856/how-to-compute-2d-log-chromaticity">How to compute 2D log-chromaticity?</a></p>
  
  <p>but it was never answered.</p>
  
  <p>(<strong>ASIDE:</strong> A guess was made that the axes must be log instead of linear, but this is incorrect as the paper uses negative coordinates, and log axes cannot be negative. Also, I was desparate and tried <code>plt.xscale('log')</code> and <code>plt.yscale('log')</code>, but it didn't work).</p>
  
  <p>This work is based off this paper:</p>
  
  <p><a href="https://www.cs.sfu.ca/~mark/ftp/Eccv04/" rel="nofollow noreferrer">https://www.cs.sfu.ca/~mark/ftp/Eccv04/</a></p>
  
  <p><em>(I re-mention it below)</em></p>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>import numpy as np
  import cv2
  import os
  import matplotlib.pyplot as plt
  
  root = r'.\path\to\root'
  root = r'my_img.jpg'
  
  if __name__ == '__main__':
  
      img = cv2.imread(os.path.join(root, fl))
  
      cv2.imshow('Original', img)
      cv2.waitKey(0)
  
      b, g, r = cv2.split(img)
  
      img_sum = np.sum(img, axis = 2) # NOTE: This dtype will be uint32.
                                      #       Each channel can be up to
                                      #       255 (dtype = uint8), but
                                      #       since uint8 can only go up
                                      #       to 255, sum naturally uint32
  
      # "Normalized" channels
      # NOTE: np.ma is the masked array library. It automatically masks
      #       inf and nan answers from result
  
      n_r = np.ma.divide(1.*r, g)
      n_b = np.ma.divide(1.*b, g)
  
      log_rg = np.ma.log( n_r )
      log_bg = np.ma.log( n_b )
  
      plt.scatter(l_rg, l_bg, s = 2)
      plt.xlabel('Log(R/G)')
      plt.ylabel('Log(B/G)')
      plt.title('2D Log Chromaticity')
      plt.show()
  </code></pre>
  
  <p><strong>Input:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/n4ZgS.png" rel="nofollow noreferrer">Color Checker Chart</a></p>
  
  <p><strong>Result:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/v0oPr.png" rel="nofollow noreferrer">My Log Chromaticity Plot</a></p>
  
  <p><strong>Expected Result:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/oISkS.png" rel="nofollow noreferrer">Finlayson Log Chromaticity Plot</a></p>
  
  <p>The expected result was taken from this paper ("Intrinsic Images by Entropy Minimization", by: Finlayson, G., et. al.):</p>
  
  <p><a href="https://www.cs.sfu.ca/~mark/ftp/Eccv04/" rel="nofollow noreferrer">https://www.cs.sfu.ca/~mark/ftp/Eccv04/</a></p>
  
  <p><em>(Paper also mentioned above)</em></p>
  
  <p><strong>Can you help me please?!</strong></p>