Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-122

Mutual Information

Problem

Compute the mutual information in bits between two same-shaped integer images.

Use the identity MI = H(a) + H(b) - H(a, b), where each entropy is the Shannon entropy of the corresponding pixel histogram. Round to 4 decimal places.

Hint

Mutual information is zero when the two images are independent.

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: 0
case 3
in: [[[0,1],[2,3]],[[0,0],[0,0]]]
expected: 0
case 4
in: [[[0,0,1,1]],[[0,1,0,1]]]
expected: 0
Starter codePython
def mutual_information(a, b):
    # Your code here
    pass

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