Loading autocnet/matcher/subpixel.py +52 −1 Original line number Diff line number Diff line Loading @@ -145,6 +145,58 @@ def check_image_size(imagesize): y = floor(y/2) return x,y def clip_roi(img, center_x, center_y, size_x=200, size_y=200, dtype="uint64"): """ Given an input image, clip a square region of interest centered on some pixel at some size. Parameters ---------- img : ndarray or object The input image to be clipped or an object with a read_array method that takes a pixels argument in the form [xstart, ystart, xstop, ystop] center_x : Numeric The x coordinate to the center of the roi center_y : Numeric The y coordinate to the center of the roi img_size : int 1/2 of the total image size. This value is the number of pixels grabbed from each side of the center Returns ------- clipped_img : ndarray The clipped image """ try: raster_size = img.raster_size except: # x,y form raster_size = img.shape[::-1] axr, ax = modf(center_x) ayr, ay = modf(center_y) if ax + size_x > raster_size[0]: size_x = floor(raster_size[0] - center_x) if ax - size_x < 0: size_x = int(ax) if ay + size_y > raster_size[1]: size_y =floor(raster_size[1] - center_y) if ay - size_y < 0: size_y = int(ay) # Read from the upper left origin pixels = [ax-size_x, ay-size_y, size_x*2, size_y*2] pixels = list(map(int, pixels)) # if isinstance(img, np.ndarray): subarray = img[pixels[1]:pixels[1] + pixels[3] + 1, pixels[0]:pixels[0] + pixels[2] + 1] else: try: subarray = img.read_array(pixels=pixels, dtype=dtype) except: return None, 0, 0 return subarray, axr, ayr def subpixel_phase(sx, sy, dx, dy, s_img, d_img, image_size=(51, 51), Loading Loading @@ -469,7 +521,6 @@ def subpixel_template_classic(sx, sy, dx, dy, return None, None, None, None shift_x, shift_y, metrics, corrmap = func(img_as_float32(d_template), img_as_float32(s_image), **kwargs) print(shift_x, shift_y) if shift_x is None: return None, None, None, None # Apply the shift and return Loading autocnet/matcher/tests/test_subpixel.py +0 −6 Original line number Diff line number Diff line Loading @@ -105,12 +105,6 @@ def test_subpixel_template_at_edge(apollo_subsets, loc, failure): func=func) assert nx == 50.5 def test_estimate_affine_transformation(): a = [[0,1], [0,0], [1,0], [1,1], [0,1]] b = [[1, 2], [1, 1], [2, 1], [2, 2], [1, 2]] transform = sp.estimate_affine_transformation(a,b) assert isinstance(transform, tf.AffineTransform) def test_subpixel_transformed_template(apollo_subsets): a = apollo_subsets[0] b = apollo_subsets[1] Loading autocnet/transformation/roi.py +19 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,22 @@ class Roi(): pixels = [pixels[0], pixels[2], pixels[1]-pixels[0]+1, pixels[3]-pixels[2]+1] data = self.data.read_array(pixels=pixels) return data def clip(self, dtype=None): """ Compatibility function that makes a call to the array property. Warning: The dtype passed in via this function resets the dtype attribute of this instance. Parameters ---------- dtype : str The datatype to be used when reading the ROI information if the read occurs through the data object using the read_array method. When using this object when the data are a numpy array the dtype has not effect. Returns ------- : ndarray The array attribute of this object. """ #self.dtype = dtype return self.array No newline at end of file autocnet/transformation/tests/test_affine.py +4 −4 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ def test_estimate_affine_transformation(): gd_base = GeoDataset('tests/test_subpixel_match/B08_012650_1780_XN_02S046W.l1.cal.destriped.crop.cub') gd_match = GeoDataset('tests/test_subpixel_match/J04_046447_1777_XI_02S046W.l1.cal.destriped.crop.cub') affine_transform = affine.estimate_affine_transformation(gd_base,gd_match, 150, 150) assert affine_transform.rotation == pytest.approx(7.36134153381208e-17, 6) assert affine_transform.shear == pytest.approx(-7.36134153381208e-17) assert affine_transform.rotation == pytest.approx(-0.0012609633370663982, 6) assert affine_transform.shear == pytest.approx(0.01262411827876344) assert affine_transform.scale[0] == pytest.approx(1.0, 6) assert affine_transform.scale[1] == pytest.approx(1.0000000000000002, 6) assert affine_transform.translation[0] == pytest.approx(0.00000000e+00, 6) assert affine_transform.translation[1] == pytest.approx(-5.68434189e-14, 6) assert affine_transform.translation[0] == pytest.approx(10.591885552140951, 6) assert affine_transform.translation[1] == pytest.approx(1.7377773467863733, 6) No newline at end of file autocnet/transformation/tests/test_roi.py +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ def test_geodata_is_valid(geodata_b): def test_center(array_with_nodata): roi = Roi(array_with_nodata, 5, 5) assert roi.center == (5,5) assert roi.center == (5.5,5.5) @pytest.mark.parametrize("ndv, truthy", [(None, True), (0, False)]) Loading Loading
autocnet/matcher/subpixel.py +52 −1 Original line number Diff line number Diff line Loading @@ -145,6 +145,58 @@ def check_image_size(imagesize): y = floor(y/2) return x,y def clip_roi(img, center_x, center_y, size_x=200, size_y=200, dtype="uint64"): """ Given an input image, clip a square region of interest centered on some pixel at some size. Parameters ---------- img : ndarray or object The input image to be clipped or an object with a read_array method that takes a pixels argument in the form [xstart, ystart, xstop, ystop] center_x : Numeric The x coordinate to the center of the roi center_y : Numeric The y coordinate to the center of the roi img_size : int 1/2 of the total image size. This value is the number of pixels grabbed from each side of the center Returns ------- clipped_img : ndarray The clipped image """ try: raster_size = img.raster_size except: # x,y form raster_size = img.shape[::-1] axr, ax = modf(center_x) ayr, ay = modf(center_y) if ax + size_x > raster_size[0]: size_x = floor(raster_size[0] - center_x) if ax - size_x < 0: size_x = int(ax) if ay + size_y > raster_size[1]: size_y =floor(raster_size[1] - center_y) if ay - size_y < 0: size_y = int(ay) # Read from the upper left origin pixels = [ax-size_x, ay-size_y, size_x*2, size_y*2] pixels = list(map(int, pixels)) # if isinstance(img, np.ndarray): subarray = img[pixels[1]:pixels[1] + pixels[3] + 1, pixels[0]:pixels[0] + pixels[2] + 1] else: try: subarray = img.read_array(pixels=pixels, dtype=dtype) except: return None, 0, 0 return subarray, axr, ayr def subpixel_phase(sx, sy, dx, dy, s_img, d_img, image_size=(51, 51), Loading Loading @@ -469,7 +521,6 @@ def subpixel_template_classic(sx, sy, dx, dy, return None, None, None, None shift_x, shift_y, metrics, corrmap = func(img_as_float32(d_template), img_as_float32(s_image), **kwargs) print(shift_x, shift_y) if shift_x is None: return None, None, None, None # Apply the shift and return Loading
autocnet/matcher/tests/test_subpixel.py +0 −6 Original line number Diff line number Diff line Loading @@ -105,12 +105,6 @@ def test_subpixel_template_at_edge(apollo_subsets, loc, failure): func=func) assert nx == 50.5 def test_estimate_affine_transformation(): a = [[0,1], [0,0], [1,0], [1,1], [0,1]] b = [[1, 2], [1, 1], [2, 1], [2, 2], [1, 2]] transform = sp.estimate_affine_transformation(a,b) assert isinstance(transform, tf.AffineTransform) def test_subpixel_transformed_template(apollo_subsets): a = apollo_subsets[0] b = apollo_subsets[1] Loading
autocnet/transformation/roi.py +19 −0 Original line number Diff line number Diff line Loading @@ -170,3 +170,22 @@ class Roi(): pixels = [pixels[0], pixels[2], pixels[1]-pixels[0]+1, pixels[3]-pixels[2]+1] data = self.data.read_array(pixels=pixels) return data def clip(self, dtype=None): """ Compatibility function that makes a call to the array property. Warning: The dtype passed in via this function resets the dtype attribute of this instance. Parameters ---------- dtype : str The datatype to be used when reading the ROI information if the read occurs through the data object using the read_array method. When using this object when the data are a numpy array the dtype has not effect. Returns ------- : ndarray The array attribute of this object. """ #self.dtype = dtype return self.array No newline at end of file
autocnet/transformation/tests/test_affine.py +4 −4 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ def test_estimate_affine_transformation(): gd_base = GeoDataset('tests/test_subpixel_match/B08_012650_1780_XN_02S046W.l1.cal.destriped.crop.cub') gd_match = GeoDataset('tests/test_subpixel_match/J04_046447_1777_XI_02S046W.l1.cal.destriped.crop.cub') affine_transform = affine.estimate_affine_transformation(gd_base,gd_match, 150, 150) assert affine_transform.rotation == pytest.approx(7.36134153381208e-17, 6) assert affine_transform.shear == pytest.approx(-7.36134153381208e-17) assert affine_transform.rotation == pytest.approx(-0.0012609633370663982, 6) assert affine_transform.shear == pytest.approx(0.01262411827876344) assert affine_transform.scale[0] == pytest.approx(1.0, 6) assert affine_transform.scale[1] == pytest.approx(1.0000000000000002, 6) assert affine_transform.translation[0] == pytest.approx(0.00000000e+00, 6) assert affine_transform.translation[1] == pytest.approx(-5.68434189e-14, 6) assert affine_transform.translation[0] == pytest.approx(10.591885552140951, 6) assert affine_transform.translation[1] == pytest.approx(1.7377773467863733, 6) No newline at end of file
autocnet/transformation/tests/test_roi.py +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ def test_geodata_is_valid(geodata_b): def test_center(array_with_nodata): roi = Roi(array_with_nodata, 5, 5) assert roi.center == (5,5) assert roi.center == (5.5,5.5) @pytest.mark.parametrize("ndv, truthy", [(None, True), (0, False)]) Loading