def test_cross_correlate_masked_output_range(): """Masked normalized cross-correlation should return between 1 and -1.""" # See random number generator for reproducible results np.random.seed(23) # Array dimensions must match along non-transformation axes, in # this case # axis 0 shape1 = (15, 4, 5) shape2 = (15, 12, 7) # Initial array ranges between -5 and 5 arr1 = 10 * np.random.random(shape1) - 5 arr2 = 10 * np.random.random(shape2) - 5 # random masks m1 = np.random.choice([True, False], arr1.shape) m2 = np.random.choice([True, False], arr2.shape) xcorr = cross_correlate_masked(arr1, arr2, m1, m2, axes=(1, 2)) # No assert array less or equal, so we add an eps # Also could not find an `assert_array_greater`, Use (-xcorr) instead eps = np.finfo(np.float).eps testing.assert_array_less(xcorr, 1 + eps) testing.assert_array_less(-xcorr, 1 + eps)
def test_ellipse_model_estimate_from_data(): data = np.array([ [264, 854], [265, 875], [268, 863], [270, 857], [275, 905], [285, 915], [305, 925], [324, 934], [335, 764], [336, 915], [345, 925], [345, 945], [354, 933], [355, 745], [364, 936], [365, 754], [375, 745], [375, 735], [385, 736], [395, 735], [394, 935], [405, 727], [415, 736], [415, 727], [425, 727], [426, 929], [435, 735], [444, 933], [445, 735], [455, 724], [465, 934], [465, 735], [475, 908], [475, 726], [485, 753], [485, 728], [492, 762], [495, 745], [491, 910], [493, 909], [499, 904], [505, 905], [504, 747], [515, 743], [516, 752], [524, 855], [525, 844], [525, 885], [533, 845], [533, 873], [535, 883], [545, 874], [543, 864], [553, 865], [553, 845], [554, 825], [554, 835], [563, 845], [565, 826], [563, 855], [563, 795], [565, 735], [573, 778], [572, 815], [574, 804], [575, 665], [575, 685], [574, 705], [574, 745], [575, 875], [572, 732], [582, 795], [579, 709], [583, 805], [583, 854], [586, 755], [584, 824], [585, 655], [581, 718], [586, 844], [585, 915], [587, 905], [594, 824], [593, 855], [590, 891], [594, 776], [596, 767], [593, 763], [603, 785], [604, 775], [603, 885], [605, 753], [605, 655], [606, 935], [603, 761], [613, 802], [613, 945], [613, 965], [615, 693], [617, 665], [623, 962], [624, 972], [625, 995], [633, 673], [633, 965], [633, 683], [633, 692], [633, 954], [634, 1016], [635, 664], [641, 804], [637, 999], [641, 956], [643, 946], [643, 926], [644, 975], [643, 655], [646, 705], [651, 664], [651, 984], [647, 665], [651, 715], [651, 725], [651, 734], [647, 809], [651, 825], [651, 873], [647, 900], [652, 917], [651, 944], [652, 742], [648, 811], [651, 994], [652, 783], [650, 911], [654, 879]]) # estimate parameters of real data model = EllipseModel() model.estimate(data) # test whether estimated parameters are smaller then 1000, so means stable assert_array_less(np.abs(model.params[:4]), np.array([2e3] * 4))
def test_ellipse_model_estimate(): for angle in range(0, 180, 15): rad = np.deg2rad(angle) # generate original data without noise model0 = EllipseModel() model0.params = (10, 20, 15, 25, rad) t = np.linspace(0, 2 * np.pi, 100) data0 = model0.predict_xy(t) # add gaussian noise to data random_state = np.random.RandomState(1234) data = data0 + random_state.normal(size=data0.shape) # estimate parameters of noisy data model_est = EllipseModel() model_est.estimate(data) # test whether estimated parameters almost equal original parameters assert_almost_equal(model0.params[:2], model_est.params[:2], 0) res = model_est.residuals(data0) assert_array_less(res, np.ones(res.shape))
def test_ellipse_model_estimate_from_data(): data = np.array([ [264, 854], [265, 875], [268, 863], [270, 857], [275, 905], [285, 915], [305, 925], [324, 934], [335, 764], [336, 915], [345, 925], [345, 945], [354, 933], [355, 745], [364, 936], [365, 754], [375, 745], [375, 735], [385, 736], [395, 735], [394, 935], [405, 727], [415, 736], [415, 727], [425, 727], [426, 929], [435, 735], [444, 933], [445, 735], [455, 724], [465, 934], [465, 735], [475, 908], [475, 726], [485, 753], [485, 728], [492, 762], [495, 745], [491, 910], [493, 909], [499, 904], [505, 905], [504, 747], [515, 743], [516, 752], [524, 855], [525, 844], [525, 885], [533, 845], [533, 873], [535, 883], [545, 874], [543, 864], [553, 865], [553, 845], [554, 825], [554, 835], [563, 845], [565, 826], [563, 855], [563, 795], [565, 735], [573, 778], [572, 815], [574, 804], [575, 665], [575, 685], [574, 705], [574, 745], [575, 875], [572, 732], [582, 795], [579, 709], [583, 805], [583, 854], [586, 755], [584, 824], [585, 655], [581, 718], [586, 844], [585, 915], [587, 905], [594, 824], [593, 855], [590, 891], [594, 776], [596, 767], [593, 763], [603, 785], [604, 775], [603, 885], [605, 753], [605, 655], [606, 935], [603, 761], [613, 802], [613, 945], [613, 965], [615, 693], [617, 665], [623, 962], [624, 972], [625, 995], [633, 673], [633, 965], [633, 683], [633, 692], [633, 954], [634, 1016], [635, 664], [641, 804], [637, 999], [641, 956], [643, 946], [643, 926], [644, 975], [643, 655], [646, 705], [651, 664], [651, 984], [647, 665], [651, 715], [651, 725], [651, 734], [647, 809], [651, 825], [651, 873], [647, 900], [652, 917], [651, 944], [652, 742], [648, 811], [651, 994], [652, 783], [650, 911], [654, 879] ], dtype=np.int32) # estimate parameters of real data model = EllipseModel() model.estimate(data) # test whether estimated parameters are smaller then 1000, so means stable assert_array_less(model.params[:4], np.full(4, 1000)) # test whether all parameters are more than 0. Negative values were the # result of an integer overflow assert_array_less(np.zeros(4), np.abs(model.params[:4]))