title: Nice Way to Visualize DCT Coefficients as an Image
body: <p>I took the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/Tr8Dn.jpg" alt="lizzards"></p>
  
  <p>Divided it into <code>8X8</code> tiles, did a 2D DCT transform on each tile and chopped them to only the first <code>30</code> coefficients on each axis. Now I'm trying to visualize the result as an image that will help my intuition on the DCT plane. </p>
  
  <p>Problems: </p>
  
  <ul>
  <li>The DCT coefficient of <code>(0,0)</code> is way larger than all the others </li>
  <li>I want to see a difference between positive and negative coefficients. </li>
  </ul>
  
  <p>So far, the best transform I found is below:</p>
  
  <pre><code>def visualize_dct(d):
      d = np.log(abs(d).clip(0.1))
      maxi, mini = d.max(), d.min()
      d = 255*(d - mini)/(maxi-mini)
      return d
  </code></pre>
  
  <p>Which gave me the image below: </p>
  
  <p><img src="https://i.stack.imgur.com/HT8iV.png" alt="dct_visualized"></p>
  
  <p>Full code here:
  <a href="http://nbviewer.ipython.org/github/ihadanny/my-py-notebooks/blob/master/img_processing_04.ipynb" rel="nofollow noreferrer">http://nbviewer.ipython.org/github/ihadanny/my-py-notebooks/blob/master/img_processing_04.ipynb</a></p>
  
  <p>Any better ideas?</p>