Calculating n-dimensional Image Entropy Python

Viewed 1992

I am trying to calculate the entropy on higher dimensional "images". The obvious approach:

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())

works but is painfully slow.

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?

I know scikit-image's entropy does a good job but only in 2D. Similarly I know matlab's entropyfilt which performs a couple hundred times faster than my current implementation.

1 Answers
Related