def test_basic(): H = joint_hist(h1, h1, std=1) D = np.zeros((255, 255), dtype=np.bool) for i in range(-3, 3): m = np.diag(np.ones(255 - abs(i)), k=i).astype(np.bool) D[m] = 1 assert_almost_equal(np.sum(H[D]), 0.97, decimal=1) assert_almost_equal(np.sum(H[~D]), 0.03, decimal=1)
import numpy as np from demo_data import chelsea from supreme.register.parzen import joint_hist, mutual_info from supreme.transform import homography import matplotlib.pyplot as plt h1 = chelsea(grey=True).astype(np.uint8) plt.suptitle('Parzen-Window Joint PDF Estimator') for n, t in enumerate([0, 0.01, 0.1]): plt.subplot(1, 3, n + 1) h2 = homography(h1, [[np.cos(t), -np.sin(t), 0], [np.sin(t), np.cos(t), 0], [0, 0, 1]]) if n == 0: plt.ylabel('Grey levels in A') plt.xlabel('Grey levels in B') H = joint_hist(h1, h2, win_size=5, std=1) S = mutual_info(H) plt.title('Rotation $%.2f^\\circ$\nS=%.5f' % ((t / np.pi * 180), S)) plt.imshow(np.log(H + 10), interpolation='nearest') plt.show()
def test_mutual_info(): H = joint_hist(h1, h1) S = mutual_info(H) assert S > 5
import numpy as np from demo_data import chelsea from supreme.register.parzen import joint_hist, mutual_info from supreme.transform import homography import matplotlib.pyplot as plt h1 = chelsea(grey=True).astype(np.uint8) plt.suptitle('Parzen-Window Joint PDF Estimator') for n, t in enumerate([0, 0.01, 0.1]): plt.subplot(1, 3, n + 1) h2 = homography( h1, [[np.cos(t), -np.sin(t), 0], [np.sin(t), np.cos(t), 0], [0, 0, 1]]) if n == 0: plt.ylabel('Grey levels in A') plt.xlabel('Grey levels in B') H = joint_hist(h1, h2, win_size=5, std=1) S = mutual_info(H) plt.title('Rotation $%.2f^\\circ$\nS=%.5f' % ((t / np.pi * 180), S)) plt.imshow(np.log(H + 10), interpolation='nearest') plt.show()
def test_mutual_info(): H = joint_hist(h1, h1) S = mutual_info(H) assert (S > 5)