Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-121

Joint Entropy of Image Pairs

Problem

Compute the joint Shannon entropy in bits of two same-shaped integer images.

Build the histogram of (a[i][j], b[i][j]) value pairs on the aligned pixels, then return -sum(p * log2(p)) rounded to 4 decimal places. An empty pair set returns 0.0.

Test cases

case 1
in: [[[0,0],[1,1]],[[0,0],[1,1]]]
expected: 1
case 2
in: [[[0,1],[0,1]],[[0,0],[1,1]]]
expected: 2
case 3
in: [[[0,1],[2,3]],[[0,1],[2,3]]]
expected: 2
case 4
in: [[[]],[[]]]
expected: 0
Starter codePython
def joint_entropy(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor