Loading autocnet/matcher/mutual_information.py +5 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ def mutual_information(reference_roi, moving_roi, affine=AffineTransform(), **kw reference_image = reference_roi.clip() walking_template = moving_roi.clip() # print(f"\nShape's \n{reference_image.shape}\n{walking_template.shape}\n--------") # if reference_roi.ndv == None or moving_roi.ndv == None: if np.isnan(reference_image).any() or np.isnan(walking_template).any(): raise Exception('Unable to process due to NaN values in the input data') Loading Loading @@ -99,8 +101,8 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, func = mutual_information image_size = (s_image.size_x * 2, s_image.size_y * 2) template_size = (d_template.size_x * 2, d_template.size_y * 2) image_size = ((s_image.size_x * 2) + 1, (s_image.size_y * 2) + 1) template_size = ((d_template.size_x * 2) + 1, (d_template.size_y * 2) + 1) y_diff = image_size[0] - template_size[0] x_diff = image_size[1] - template_size[1] Loading @@ -119,7 +121,6 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, for i in range(starting_y, ending_y): for j in range(starting_x, ending_x): s_image.x = (j) s_image.y = (i) Loading Loading @@ -154,4 +155,3 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, x += subpixel_x_shift new_affine = AffineTransform(translation=(-x, -y)) return new_affine, float(max_corr), corr_map No newline at end of file # return float(x), float(y), float(max_corr), corr_map No newline at end of file autocnet/matcher/tests/test_mutual_information.py +5 −20 Original line number Diff line number Diff line Loading @@ -21,31 +21,16 @@ def test_bad_mi(): assert corrilation == pytest.approx(0) def test_mutual_information(): d_template = np.array([[i for i in range(50, 100)] for j in range(50)]) s_image = np.ones((100, 100)) s_image[25:75, 25:75] = d_template d_template = Roi(d_template, 25, 25, 25, 25, ndv=22222222) s_image = Roi(s_image, 50, 50, 25, 25, ndv=22222222) affine, max_corr, corr_map = mutual_information.mutual_information_match(d_template, s_image, bins=20) assert max_corr == 2.9755967600033015 assert corr_map.shape == (50, 50) assert np.min(corr_map) >= 0.0 #TODO add assert test for affine and odd sized s_image def test_mutual_information_odd_sized_s_image(): d_template = np.array([[i for i in range(50, 101)] for j in range(51)]) s_image = np.ones((101, 101)) s_image[25:76, 25:76] = d_template d_template = Roi(d_template, 26, 26, 26, 26, ndv=22222222) s_image = Roi(s_image, 51, 51, 26, 26, ndv=22222222) d_template = Roi(d_template, 25, 25, 25, 25, ndv=22222222) s_image = Roi(s_image, 50, 50, 25, 25, ndv=22222222) affine, max_corr, corr_map = mutual_information.mutual_information_match(d_template, s_image, bins=20) assert max_corr == 2.9755967600033015 assert affine.params[0][2] == -0.45017566300973355 assert affine.params[1][2] == -0.5000000000000002 assert max_corr == 2.9763186763296856 assert corr_map.shape == (51, 51) assert np.min(corr_map) >= 0.0 No newline at end of file autocnet/transformation/roi.py +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ class Roi(): """ pixels = self.image_extent if isinstance(self.data, np.ndarray): data = self.data[pixels[2]:pixels[3],pixels[0]:pixels[1]] data = self.data[pixels[2]:pixels[3]+1,pixels[0]:pixels[1]+1] else: # Have to reformat to [xstart, ystart, xnumberpixels, ynumberpixels] # TODO: I think this will result in an incorrect obj.center when the passed data is a GeoDataset Loading Loading
autocnet/matcher/mutual_information.py +5 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ def mutual_information(reference_roi, moving_roi, affine=AffineTransform(), **kw reference_image = reference_roi.clip() walking_template = moving_roi.clip() # print(f"\nShape's \n{reference_image.shape}\n{walking_template.shape}\n--------") # if reference_roi.ndv == None or moving_roi.ndv == None: if np.isnan(reference_image).any() or np.isnan(walking_template).any(): raise Exception('Unable to process due to NaN values in the input data') Loading Loading @@ -99,8 +101,8 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, func = mutual_information image_size = (s_image.size_x * 2, s_image.size_y * 2) template_size = (d_template.size_x * 2, d_template.size_y * 2) image_size = ((s_image.size_x * 2) + 1, (s_image.size_y * 2) + 1) template_size = ((d_template.size_x * 2) + 1, (d_template.size_y * 2) + 1) y_diff = image_size[0] - template_size[0] x_diff = image_size[1] - template_size[1] Loading @@ -119,7 +121,6 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, for i in range(starting_y, ending_y): for j in range(starting_x, ending_x): s_image.x = (j) s_image.y = (i) Loading Loading @@ -154,4 +155,3 @@ def mutual_information_match(d_template, s_image, subpixel_size=3, x += subpixel_x_shift new_affine = AffineTransform(translation=(-x, -y)) return new_affine, float(max_corr), corr_map No newline at end of file # return float(x), float(y), float(max_corr), corr_map No newline at end of file
autocnet/matcher/tests/test_mutual_information.py +5 −20 Original line number Diff line number Diff line Loading @@ -21,31 +21,16 @@ def test_bad_mi(): assert corrilation == pytest.approx(0) def test_mutual_information(): d_template = np.array([[i for i in range(50, 100)] for j in range(50)]) s_image = np.ones((100, 100)) s_image[25:75, 25:75] = d_template d_template = Roi(d_template, 25, 25, 25, 25, ndv=22222222) s_image = Roi(s_image, 50, 50, 25, 25, ndv=22222222) affine, max_corr, corr_map = mutual_information.mutual_information_match(d_template, s_image, bins=20) assert max_corr == 2.9755967600033015 assert corr_map.shape == (50, 50) assert np.min(corr_map) >= 0.0 #TODO add assert test for affine and odd sized s_image def test_mutual_information_odd_sized_s_image(): d_template = np.array([[i for i in range(50, 101)] for j in range(51)]) s_image = np.ones((101, 101)) s_image[25:76, 25:76] = d_template d_template = Roi(d_template, 26, 26, 26, 26, ndv=22222222) s_image = Roi(s_image, 51, 51, 26, 26, ndv=22222222) d_template = Roi(d_template, 25, 25, 25, 25, ndv=22222222) s_image = Roi(s_image, 50, 50, 25, 25, ndv=22222222) affine, max_corr, corr_map = mutual_information.mutual_information_match(d_template, s_image, bins=20) assert max_corr == 2.9755967600033015 assert affine.params[0][2] == -0.45017566300973355 assert affine.params[1][2] == -0.5000000000000002 assert max_corr == 2.9763186763296856 assert corr_map.shape == (51, 51) assert np.min(corr_map) >= 0.0 No newline at end of file
autocnet/transformation/roi.py +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ class Roi(): """ pixels = self.image_extent if isinstance(self.data, np.ndarray): data = self.data[pixels[2]:pixels[3],pixels[0]:pixels[1]] data = self.data[pixels[2]:pixels[3]+1,pixels[0]:pixels[1]+1] else: # Have to reformat to [xstart, ystart, xnumberpixels, ynumberpixels] # TODO: I think this will result in an incorrect obj.center when the passed data is a GeoDataset Loading