title: Mutual information and joint entropy of two images - MATLAB
body: <p>I have two black and white images and I need to calculate the mutual information. </p>
  
  <pre><code>Image 1 = X 
  Image 2 = Y
  </code></pre>
  
  <p>I know that the mutual information can be defined as:</p>
  
  <pre><code>MI = entropy(X) + entropy(Y) - JointEntropy(X,Y)
  </code></pre>
  
  <p>MATLAB already has built-in functions to calculate the entropy but not to calculate the joint entropy. I guess the true question is: How do I calculate the joint entropy of two images? </p>
  
  <p>Here is an example of the images I'd like to find the joint entropy of:</p>
  
  <pre><code>X =
  
  0    0    0    0    0    0
  0    0    1    1    0    0
  0    0    1    1    0    0
  0    0    0    0    0    0
  0    0    0    0    0    0
  
  Y =
  
  0    0    0    0    0    0 
  0    0    0.38 0.82 0.38 0.04 
  0    0    0.32 0.82 0.68 0.17
  0    0    0.04 0.14 0.11 0 
  0    0    0    0    0    0
  </code></pre>