Hi Yiyuan,
You probably missed "1, 0" in P(l, m, 1, 0), which requires distance being 1 and direction being 0 (theta=0 is actually the direction to the right). I think H also assumes d=1 and theta=0. For example, in the matrix there are four 0-value pixels with a 0-value neighbor on its right, so H(0,0) is 4.
Hope this help!
You probably missed "1, 0" in P(l, m, 1, 0), which requires distance being 1 and direction being 0 (theta=0 is actually the direction to the right). I think H also assumes d=1 and theta=0. For example, in the matrix there are four 0-value pixels with a 0-value neighbor on its right, so H(0,0) is 4.
Hope this help!