title: Calculating n-dimensional Image Entropy Python
body: <p>I am trying to calculate the entropy on higher dimensional "images". The obvious approach:</p>
  
  <pre><code>from scipy.stats import entropy
  
  kernel_radius=2
  entropy_stack = np.zeros(Stack.shape)
  for ii in range(kernel_radius,entropy_stack.shape[0]-kernel_radius):
      for jj in range(kernel_radius,entropy_stack.shape[1]-kernel_radius):
          for kk in range(kernel_radius,entropy_stack.shape[2]-kernel_radius):    
              entropy_stack[ii,jj,kk]=entropy(Stack[ii-kernel_radius:ii+kernel_radius,jj-kernel_radius:jj+kernel_radius,kk-kernel_radius:kk+kernel_radius].flatten())
  </code></pre>
  
  <p>works but is painfully slow. </p>
  
  <p>Are there any implementation tricks to calculating entropy in higher dimensional images? even better: are there any packages with an optimized version of this function?</p>
  
  <p>I know scikit-image's <code>entropy</code> does a good job but only in 2D. Similarly I know matlab's <code>entropyfilt</code> which performs a couple hundred times faster than my current implementation.</p>