Loading autocnet/matcher/mutual_information.py +20 −11 Original line number Diff line number Diff line Loading @@ -3,8 +3,9 @@ from math import floor import numpy as np from scipy.ndimage.measurements import center_of_mass from skimage.transform import AffineTransform def mutual_information(t1, t2, **kwargs): def mutual_information(reference_roi, walking_roi, affine=AffineTransform(), **kwargs): """ Computes the correlation coefficient between two images using a histogram comparison (Mutual information for joint histograms). The corr_map coefficient Loading @@ -13,12 +14,13 @@ def mutual_information(t1, t2, **kwargs): Parameters ---------- t1 : ndarray reference_roi : Roi First image to use in the histogram comparison t2 : ndarray moving_roi : Roi Second image to use in the histogram comparison Returns ------- Loading @@ -31,15 +33,22 @@ def mutual_information(t1, t2, **kwargs): numpy.histogram2d : for the kwargs that can be passed to the comparison """ if np.isnan(t1).any() or np.isnan(t2).any(): reference_image = reference_roi.clip() walking_template = walking_roi.clip(affine) # walking_template = tf.warp(walking_template, affine, order=3) if reference_roi.ndv == None or walking_roi.ndv == None: print('Unable to process due to NaN values in the input data') return if t1.shape != t2.shape: # print(reference_roi.size_y, walking_roi.size_y) if reference_roi.size_y != walking_roi.size_y and reference_roi.size_x != walking_roi.size_x: print('Unable compute MI. Image sizes are not identical.') return hgram, x_edges, y_edges = np.histogram2d(t1.ravel(),t2.ravel(), **kwargs) hgram, x_edges, y_edges = np.histogram2d(reference_image.ravel(), walking_template.ravel(), **kwargs) # Convert bins counts to probability values pxy = hgram / float(np.sum(hgram)) Loading autocnet/matcher/tests/test_mutual_information.py +2 −2 Original line number Diff line number Diff line Loading @@ -3,14 +3,14 @@ import os import sys import unittest from unittest.mock import patch from autocnet.transformation.roi import Roi import pytest import numpy as np from .. import mutual_information def test_good_mi(): test_image1 = np.array([[i for i in range(50)] for j in range(50)]) test_image1 = Roi(np.array([[i for i in range(50)] for j in range(50)]), 25, 25, 25, 25, ndv=22222222) corrilation = mutual_information.mutual_information(test_image1, test_image1) assert corrilation == pytest.approx(2.30258509299404) Loading autocnet/transformation/affine.py +7 −3 Original line number Diff line number Diff line Loading @@ -65,9 +65,13 @@ def estimate_affine_transformation(reference_image, x_coords = [base_startx, base_startx, base_stopx, base_stopx, bcenter_x] y_coords = [base_starty, base_stopy, base_stopy, base_starty, bcenter_y] try: # Dispatch to the sensor to get the a priori pixel location in the input image lons, lats = isis.image_to_ground(reference_image.file_name, x_coords, y_coords, allowoutside=True) xs, ys = isis.ground_to_image(moving_image.file_name, lons, lats, allowoutside=True) except Exception as e: print(e.stderr) raise e # Check for any coords that do not project between images base_gcps = [] Loading autocnet/transformation/roi.py +1 −2 Original line number Diff line number Diff line from math import modf, floor import numpy as np from autocnet.transformation import dtypes import pvl class Roi(): Loading Loading
autocnet/matcher/mutual_information.py +20 −11 Original line number Diff line number Diff line Loading @@ -3,8 +3,9 @@ from math import floor import numpy as np from scipy.ndimage.measurements import center_of_mass from skimage.transform import AffineTransform def mutual_information(t1, t2, **kwargs): def mutual_information(reference_roi, walking_roi, affine=AffineTransform(), **kwargs): """ Computes the correlation coefficient between two images using a histogram comparison (Mutual information for joint histograms). The corr_map coefficient Loading @@ -13,12 +14,13 @@ def mutual_information(t1, t2, **kwargs): Parameters ---------- t1 : ndarray reference_roi : Roi First image to use in the histogram comparison t2 : ndarray moving_roi : Roi Second image to use in the histogram comparison Returns ------- Loading @@ -31,15 +33,22 @@ def mutual_information(t1, t2, **kwargs): numpy.histogram2d : for the kwargs that can be passed to the comparison """ if np.isnan(t1).any() or np.isnan(t2).any(): reference_image = reference_roi.clip() walking_template = walking_roi.clip(affine) # walking_template = tf.warp(walking_template, affine, order=3) if reference_roi.ndv == None or walking_roi.ndv == None: print('Unable to process due to NaN values in the input data') return if t1.shape != t2.shape: # print(reference_roi.size_y, walking_roi.size_y) if reference_roi.size_y != walking_roi.size_y and reference_roi.size_x != walking_roi.size_x: print('Unable compute MI. Image sizes are not identical.') return hgram, x_edges, y_edges = np.histogram2d(t1.ravel(),t2.ravel(), **kwargs) hgram, x_edges, y_edges = np.histogram2d(reference_image.ravel(), walking_template.ravel(), **kwargs) # Convert bins counts to probability values pxy = hgram / float(np.sum(hgram)) Loading
autocnet/matcher/tests/test_mutual_information.py +2 −2 Original line number Diff line number Diff line Loading @@ -3,14 +3,14 @@ import os import sys import unittest from unittest.mock import patch from autocnet.transformation.roi import Roi import pytest import numpy as np from .. import mutual_information def test_good_mi(): test_image1 = np.array([[i for i in range(50)] for j in range(50)]) test_image1 = Roi(np.array([[i for i in range(50)] for j in range(50)]), 25, 25, 25, 25, ndv=22222222) corrilation = mutual_information.mutual_information(test_image1, test_image1) assert corrilation == pytest.approx(2.30258509299404) Loading
autocnet/transformation/affine.py +7 −3 Original line number Diff line number Diff line Loading @@ -65,9 +65,13 @@ def estimate_affine_transformation(reference_image, x_coords = [base_startx, base_startx, base_stopx, base_stopx, bcenter_x] y_coords = [base_starty, base_stopy, base_stopy, base_starty, bcenter_y] try: # Dispatch to the sensor to get the a priori pixel location in the input image lons, lats = isis.image_to_ground(reference_image.file_name, x_coords, y_coords, allowoutside=True) xs, ys = isis.ground_to_image(moving_image.file_name, lons, lats, allowoutside=True) except Exception as e: print(e.stderr) raise e # Check for any coords that do not project between images base_gcps = [] Loading
autocnet/transformation/roi.py +1 −2 Original line number Diff line number Diff line from math import modf, floor import numpy as np from autocnet.transformation import dtypes import pvl class Roi(): Loading