Loading autocnet/matcher/subpixel.py +3 −6 Original line number Diff line number Diff line Loading @@ -312,9 +312,7 @@ def subpixel_template(reference_roi, moving_roi, affine=tf.AffineTransform(), mo # In ISIS, the reference image is the search and moving image is the pattern. ref_clip = reference_roi.clip() moving_clip = moving_roi.clip() moving_clip = tf.warp(moving_clip, affine, order=3, mode=mode) moving_clip = moving_roi.clip(affine) if moving_clip.var() == 0: warnings.warn('Input ROI has no variance.') Loading @@ -322,8 +320,7 @@ def subpixel_template(reference_roi, moving_roi, affine=tf.AffineTransform(), mo if (ref_clip is None) or (moving_clip is None): return None, None, None shift_x, shift_y, metrics, corrmap = func(img_as_float32(moving_clip), img_as_float32(ref_clip), **kwargs) shift_x, shift_y, metrics, corrmap = func(moving_clip, ref_clip, **kwargs) if shift_x is None: return None, None, None Loading autocnet/matcher/tests/test_subpixel.py +15 −12 Original line number Diff line number Diff line Loading @@ -142,13 +142,13 @@ def test_check_image_size(data, expected): assert sp.check_image_size(data) == expected @pytest.mark.parametrize("x, y, x1, y1, image_size, template_size, expected",[ (4, 3, 4, 2, (5,5), (3,3), (0,-1)), (4, 3, 4, 2, (7,7), (3,3), (0,-2)), # Increase the search image size (4, 3, 4, 2, (7,7), (5,5), (0,-2)), # Increase the template size (4, 3, 3, 2, (7,7), (3,3), (-1,-2)), # Move point in the x-axis (4, 3, 5, 3, (7,7), (3,3), (1,-2)), # Move point in the other x-direction (4, 3, 4, 1, (7,7), (3,3), (0, -2)), # Move point negative in the y-axis (4, 3, 4, 3, (7,7), (3,3), (0,-2)) # Move point positive in the y-axis (4, 3, 4, 3, (3,3), (2,2), (4,3)), (4, 3, 4, 3, (3,3), (2,2), (4,3)), # Increase the search image size (4, 3, 4, 3, (3,3), (2,2), (4,3)), # Increase the template size (4, 3, 3, 3, (3,3), (2,2), (4,3)), # Move point in the x-axis (4, 3, 5, 4, (3,3), (2,2), (4,3)), # Move point in the other x-direction (4, 3, 4, 2, (3,3), (2,2), (4,3)), # Move point negative in the y-axis (4, 3, 4, 4, (3,3), (2,2), (4,3)) # Move point positive in the y-axis ]) def test_subpixel_template_cooked(x, y, x1, y1, image_size, template_size, expected): Loading @@ -168,17 +168,22 @@ def test_subpixel_template_cooked(x, y, x1, y1, image_size, template_size, expec # Should yield (-3, 3) offset from image center t_shape = np.array(((0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 1, 1, 1, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0)), dtype=np.uint8) ref_roi = roi.Roi(test_image, x, y, *image_size) moving_roi = roi.Roi(t_shape, x1, y1, *template_size) new_affine, corr, corrmap = sp.subpixel_template(ref_roi, moving_roi, upsampling=1) assert corr >= 0.8 # geq because sometime returning weird float > 1 from OpenCV assert new_affine.translation[0] == expected[0] assert new_affine.translation[1] == expected[1] print(new_affine) nx, ny = new_affine.inverse([x1,y1])[0] # should be 1.0 assert corr >= .99 # geq because sometime returning weird float > 1 from OpenCV assert nx == expected[0] assert ny == expected[1] @pytest.mark.parametrize("x, y, x1, y1, image_size, expected",[ (4, 3, 3, 2, (1,1), (3,2)), Loading Loading @@ -217,8 +222,6 @@ def test_subpixel_phase_cooked(x, y, x1, y1, image_size, expected): walking_roi = roi.Roi(t_shape, x1, y1, size_x=image_size[0], size_y=image_size[1]) affine, metrics, _ = sp.subpixel_phase(reference_roi, walking_roi) print(affine) dx, dy = affine.inverse((x1, y1))[0] print(affine) assert dx == expected[0] assert dy == expected[1] autocnet/transformation/roi.py +5 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from math import modf, floor import numpy as np from skimage import transform as tf from skimage.util import img_as_float32 class Roi(): """ Loading Loading @@ -134,7 +135,8 @@ class Roi(): right_x = raster_size[0] if bottom_y > raster_size[1]: bottom_y = raster_size[1] print("extents:", list(map(int, [left_x, right_x, top_y, bottom_y]))) print("center:", self.x, self.y, self.size_x, self.size_y) return list(map(int, [left_x, right_x, top_y, bottom_y])) @property Loading Loading @@ -168,7 +170,7 @@ class Roi(): # TODO: I think this will result in an incorrect obj.center when the passed data is a GeoDataset pixels = [pixels[0], pixels[2], pixels[1]-pixels[0]+1, pixels[3]-pixels[2]+1] data = self.data.read_array(pixels=pixels) return data return img_as_float32(data) def clip(self, affine=None, dtype=None, mode="reflect"): """ Loading Loading @@ -201,4 +203,4 @@ class Roi(): transformed_array = tf.warp(array_to_warp, affine, order=3, mode=mode) return transformed_array return self.array return img_as_float32(self.array) Loading
autocnet/matcher/subpixel.py +3 −6 Original line number Diff line number Diff line Loading @@ -312,9 +312,7 @@ def subpixel_template(reference_roi, moving_roi, affine=tf.AffineTransform(), mo # In ISIS, the reference image is the search and moving image is the pattern. ref_clip = reference_roi.clip() moving_clip = moving_roi.clip() moving_clip = tf.warp(moving_clip, affine, order=3, mode=mode) moving_clip = moving_roi.clip(affine) if moving_clip.var() == 0: warnings.warn('Input ROI has no variance.') Loading @@ -322,8 +320,7 @@ def subpixel_template(reference_roi, moving_roi, affine=tf.AffineTransform(), mo if (ref_clip is None) or (moving_clip is None): return None, None, None shift_x, shift_y, metrics, corrmap = func(img_as_float32(moving_clip), img_as_float32(ref_clip), **kwargs) shift_x, shift_y, metrics, corrmap = func(moving_clip, ref_clip, **kwargs) if shift_x is None: return None, None, None Loading
autocnet/matcher/tests/test_subpixel.py +15 −12 Original line number Diff line number Diff line Loading @@ -142,13 +142,13 @@ def test_check_image_size(data, expected): assert sp.check_image_size(data) == expected @pytest.mark.parametrize("x, y, x1, y1, image_size, template_size, expected",[ (4, 3, 4, 2, (5,5), (3,3), (0,-1)), (4, 3, 4, 2, (7,7), (3,3), (0,-2)), # Increase the search image size (4, 3, 4, 2, (7,7), (5,5), (0,-2)), # Increase the template size (4, 3, 3, 2, (7,7), (3,3), (-1,-2)), # Move point in the x-axis (4, 3, 5, 3, (7,7), (3,3), (1,-2)), # Move point in the other x-direction (4, 3, 4, 1, (7,7), (3,3), (0, -2)), # Move point negative in the y-axis (4, 3, 4, 3, (7,7), (3,3), (0,-2)) # Move point positive in the y-axis (4, 3, 4, 3, (3,3), (2,2), (4,3)), (4, 3, 4, 3, (3,3), (2,2), (4,3)), # Increase the search image size (4, 3, 4, 3, (3,3), (2,2), (4,3)), # Increase the template size (4, 3, 3, 3, (3,3), (2,2), (4,3)), # Move point in the x-axis (4, 3, 5, 4, (3,3), (2,2), (4,3)), # Move point in the other x-direction (4, 3, 4, 2, (3,3), (2,2), (4,3)), # Move point negative in the y-axis (4, 3, 4, 4, (3,3), (2,2), (4,3)) # Move point positive in the y-axis ]) def test_subpixel_template_cooked(x, y, x1, y1, image_size, template_size, expected): Loading @@ -168,17 +168,22 @@ def test_subpixel_template_cooked(x, y, x1, y1, image_size, template_size, expec # Should yield (-3, 3) offset from image center t_shape = np.array(((0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 1, 1, 1, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0, 0, 0)), dtype=np.uint8) ref_roi = roi.Roi(test_image, x, y, *image_size) moving_roi = roi.Roi(t_shape, x1, y1, *template_size) new_affine, corr, corrmap = sp.subpixel_template(ref_roi, moving_roi, upsampling=1) assert corr >= 0.8 # geq because sometime returning weird float > 1 from OpenCV assert new_affine.translation[0] == expected[0] assert new_affine.translation[1] == expected[1] print(new_affine) nx, ny = new_affine.inverse([x1,y1])[0] # should be 1.0 assert corr >= .99 # geq because sometime returning weird float > 1 from OpenCV assert nx == expected[0] assert ny == expected[1] @pytest.mark.parametrize("x, y, x1, y1, image_size, expected",[ (4, 3, 3, 2, (1,1), (3,2)), Loading Loading @@ -217,8 +222,6 @@ def test_subpixel_phase_cooked(x, y, x1, y1, image_size, expected): walking_roi = roi.Roi(t_shape, x1, y1, size_x=image_size[0], size_y=image_size[1]) affine, metrics, _ = sp.subpixel_phase(reference_roi, walking_roi) print(affine) dx, dy = affine.inverse((x1, y1))[0] print(affine) assert dx == expected[0] assert dy == expected[1]
autocnet/transformation/roi.py +5 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from math import modf, floor import numpy as np from skimage import transform as tf from skimage.util import img_as_float32 class Roi(): """ Loading Loading @@ -134,7 +135,8 @@ class Roi(): right_x = raster_size[0] if bottom_y > raster_size[1]: bottom_y = raster_size[1] print("extents:", list(map(int, [left_x, right_x, top_y, bottom_y]))) print("center:", self.x, self.y, self.size_x, self.size_y) return list(map(int, [left_x, right_x, top_y, bottom_y])) @property Loading Loading @@ -168,7 +170,7 @@ class Roi(): # TODO: I think this will result in an incorrect obj.center when the passed data is a GeoDataset pixels = [pixels[0], pixels[2], pixels[1]-pixels[0]+1, pixels[3]-pixels[2]+1] data = self.data.read_array(pixels=pixels) return data return img_as_float32(data) def clip(self, affine=None, dtype=None, mode="reflect"): """ Loading Loading @@ -201,4 +203,4 @@ class Roi(): transformed_array = tf.warp(array_to_warp, affine, order=3, mode=mode) return transformed_array return self.array return img_as_float32(self.array)