Loading autocnet/matcher/naive_template.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -135,7 +135,7 @@ def pattern_match(template, image, upsampling=8, metric=cv2.TM_CCOEFF_NORMED, er if metric == cv2.TM_SQDIFF or metric == cv2.TM_SQDIFF_NORMED: if metric == cv2.TM_SQDIFF or metric == cv2.TM_SQDIFF_NORMED: matched_y, matched_x = np.unravel_index(np.argmin(result), result.shape) matched_y, matched_x = np.unravel_index(np.argmin(result), result.shape) else: else: matched_y, matched_x = np.unravel_index(np.argmax(result), result.shape) matched_x, matched_y = np.unravel_index(np.argmax(result), result.shape) # The center of the template is the origin # The center of the template is the origin original_y = (u_template.shape[0] - 1) // 2 original_y = (u_template.shape[0] - 1) // 2 Loading autocnet/matcher/subpixel.py +14 −9 Original line number Original line Diff line number Diff line Loading @@ -261,8 +261,7 @@ def subpixel_template(reference_roi, # In ISIS, the reference image is the search and moving image is the pattern. # In ISIS, the reference image is the search and moving image is the pattern. ref_clip = reference_roi.clip() moving_clip = moving_roi.clip(affine) if moving_clip.var() == 0: if moving_clip.var() == 0: warnings.warn('Input ROI has no variance.') warnings.warn('Input ROI has no variance.') return [None] * 3 return [None] * 3 Loading @@ -273,9 +272,15 @@ def subpixel_template(reference_roi, if matcher_shift_x is None: if matcher_shift_x is None: return None, None, None return None, None, None print(matcher_shift_x, matcher_shift_y) new_image_x, new_image_y = moving_roi.roi_coords_to_image_coords(matcher_shift_x, matcher_shift_y) print('Shifts: ', matcher_shift_x, matcher_shift_y, metrics) print(new_image_x, new_image_y) new_affine = tf.AffineTransform(translation=(new_image_x - moving_roi.x, new_image_y - moving_roi.y)) # Transformation of the ROI center if the clip applies a non-identity affine transformation return new_affine, metrics, corrmap """ # Transformation of the ROI center if the clip applies a non-identity affine transformation affine_transformed_center_x, affine_transformed_center_y = affine((moving_roi.center[0], moving_roi.center[1]))[0] affine_transformed_center_x, affine_transformed_center_y = affine((moving_roi.center[0], moving_roi.center[1]))[0] Loading @@ -283,10 +288,10 @@ def subpixel_template(reference_roi, new_center_y = affine_transformed_center_y + matcher_shift_y new_center_y = affine_transformed_center_y + matcher_shift_y translation_x, translation_y = affine.inverse((new_center_x, new_center_y))[0] translation_x, translation_y = affine.inverse((new_center_x, new_center_y))[0] new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) new_affine = tf.AffineTransform(translation=(translation_x, translation_y))""" """# Apply the shift to the center of the moving roi to the center of the reference ROI in index space. One pixel == one index (unitless). # Apply the shift to the center of the moving roi to the center of the reference ROI in index space. One pixel == one index (unitless). new_affine_transformed_center_x = moving_roi.center[0] + matcher_shift_x #Center is indices. new_affine_transformed_center_x = moving_roi.center[0] + matcher_shift_x #Center is indices. new_affine_transformed_center_y = moving_roi.center[1] + matcher_shift_y new_affine_transformed_center_y = moving_roi.center[1] + matcher_shift_y Loading @@ -302,11 +307,11 @@ def subpixel_template(reference_roi, # These are the inverse of the translation so that the caller can use affine() to # These are the inverse of the translation so that the caller can use affine() to # apply the proper translation. Otherwise, the caller would need to use affine.inverse # apply the proper translation. Otherwise, the caller would need to use affine.inverse translation_x = -(moving_roi.center[0] - inverse_transformed_affine_center_x) translation_x = -(moving_roi.center[0] - inverse_transformed_affine_center_x) translation_y = -(moving_roi.center[1] - inverse_transformed_affine_center_y)""" translation_y = -(moving_roi.center[1] - inverse_transformed_affine_center_y) #translation_x, translation_y = affine.inverse((matcher_shift_x, matcher_shift_y))[0] """#translation_x, translation_y = affine.inverse((matcher_shift_x, matcher_shift_y))[0]""" #new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) return new_affine, metrics, corrmap return new_affine, metrics, corrmap Loading autocnet/transformation/roi.py +10 −6 Original line number Original line Diff line number Diff line Loading @@ -46,20 +46,25 @@ class Roi(): self.data = data self.data = data self.x = x self.x = x self.y = y self.y = y self._affine = tf.AffineTransform(translation=(self._remainder_x, self._remainder_y)) self.size_x = size_x self.size_x = size_x self.size_y = size_y self.size_y = size_y self.ndv = ndv self.ndv = ndv self._ndv_threshold = ndv_threshold self._ndv_threshold = ndv_threshold self.buffer = buffer self.buffer = buffer def roi_coords_to_image_coords(self, x, y): """ Given coordinates in ROI pixel space, return the coordinates in image coordinate space. """ return self.affine((x, y))[0] @property @property def affine(self): def affine(self): """ """ This affine sets the origin of the ROI to be (0,0). This affine sets the origin of the ROI to be (0,0). """ """ return self._affine return tf.AffineTransform(translation=(self.x, self.y)) @property @property def x(self): def x(self): Loading Loading @@ -151,9 +156,8 @@ class Roi(): @property @property def center(self): def center(self): return (0,0) ie = self.image_extent #ie = self.image_extent return ((ie[1] - ie[0])-1)/2. + 0.5, ((ie[3]-ie[2])-1)/2. + 0.5 #return ((ie[1] - ie[0])-1)/2. + 0.5, ((ie[3]-ie[2])-1)/2. + 0.5 @property @property def is_valid(self): def is_valid(self): Loading Loading
autocnet/matcher/naive_template.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -135,7 +135,7 @@ def pattern_match(template, image, upsampling=8, metric=cv2.TM_CCOEFF_NORMED, er if metric == cv2.TM_SQDIFF or metric == cv2.TM_SQDIFF_NORMED: if metric == cv2.TM_SQDIFF or metric == cv2.TM_SQDIFF_NORMED: matched_y, matched_x = np.unravel_index(np.argmin(result), result.shape) matched_y, matched_x = np.unravel_index(np.argmin(result), result.shape) else: else: matched_y, matched_x = np.unravel_index(np.argmax(result), result.shape) matched_x, matched_y = np.unravel_index(np.argmax(result), result.shape) # The center of the template is the origin # The center of the template is the origin original_y = (u_template.shape[0] - 1) // 2 original_y = (u_template.shape[0] - 1) // 2 Loading
autocnet/matcher/subpixel.py +14 −9 Original line number Original line Diff line number Diff line Loading @@ -261,8 +261,7 @@ def subpixel_template(reference_roi, # In ISIS, the reference image is the search and moving image is the pattern. # In ISIS, the reference image is the search and moving image is the pattern. ref_clip = reference_roi.clip() moving_clip = moving_roi.clip(affine) if moving_clip.var() == 0: if moving_clip.var() == 0: warnings.warn('Input ROI has no variance.') warnings.warn('Input ROI has no variance.') return [None] * 3 return [None] * 3 Loading @@ -273,9 +272,15 @@ def subpixel_template(reference_roi, if matcher_shift_x is None: if matcher_shift_x is None: return None, None, None return None, None, None print(matcher_shift_x, matcher_shift_y) new_image_x, new_image_y = moving_roi.roi_coords_to_image_coords(matcher_shift_x, matcher_shift_y) print('Shifts: ', matcher_shift_x, matcher_shift_y, metrics) print(new_image_x, new_image_y) new_affine = tf.AffineTransform(translation=(new_image_x - moving_roi.x, new_image_y - moving_roi.y)) # Transformation of the ROI center if the clip applies a non-identity affine transformation return new_affine, metrics, corrmap """ # Transformation of the ROI center if the clip applies a non-identity affine transformation affine_transformed_center_x, affine_transformed_center_y = affine((moving_roi.center[0], moving_roi.center[1]))[0] affine_transformed_center_x, affine_transformed_center_y = affine((moving_roi.center[0], moving_roi.center[1]))[0] Loading @@ -283,10 +288,10 @@ def subpixel_template(reference_roi, new_center_y = affine_transformed_center_y + matcher_shift_y new_center_y = affine_transformed_center_y + matcher_shift_y translation_x, translation_y = affine.inverse((new_center_x, new_center_y))[0] translation_x, translation_y = affine.inverse((new_center_x, new_center_y))[0] new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) new_affine = tf.AffineTransform(translation=(translation_x, translation_y))""" """# Apply the shift to the center of the moving roi to the center of the reference ROI in index space. One pixel == one index (unitless). # Apply the shift to the center of the moving roi to the center of the reference ROI in index space. One pixel == one index (unitless). new_affine_transformed_center_x = moving_roi.center[0] + matcher_shift_x #Center is indices. new_affine_transformed_center_x = moving_roi.center[0] + matcher_shift_x #Center is indices. new_affine_transformed_center_y = moving_roi.center[1] + matcher_shift_y new_affine_transformed_center_y = moving_roi.center[1] + matcher_shift_y Loading @@ -302,11 +307,11 @@ def subpixel_template(reference_roi, # These are the inverse of the translation so that the caller can use affine() to # These are the inverse of the translation so that the caller can use affine() to # apply the proper translation. Otherwise, the caller would need to use affine.inverse # apply the proper translation. Otherwise, the caller would need to use affine.inverse translation_x = -(moving_roi.center[0] - inverse_transformed_affine_center_x) translation_x = -(moving_roi.center[0] - inverse_transformed_affine_center_x) translation_y = -(moving_roi.center[1] - inverse_transformed_affine_center_y)""" translation_y = -(moving_roi.center[1] - inverse_transformed_affine_center_y) #translation_x, translation_y = affine.inverse((matcher_shift_x, matcher_shift_y))[0] """#translation_x, translation_y = affine.inverse((matcher_shift_x, matcher_shift_y))[0]""" #new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) new_affine = tf.AffineTransform(translation=(translation_x, translation_y)) return new_affine, metrics, corrmap return new_affine, metrics, corrmap Loading
autocnet/transformation/roi.py +10 −6 Original line number Original line Diff line number Diff line Loading @@ -46,20 +46,25 @@ class Roi(): self.data = data self.data = data self.x = x self.x = x self.y = y self.y = y self._affine = tf.AffineTransform(translation=(self._remainder_x, self._remainder_y)) self.size_x = size_x self.size_x = size_x self.size_y = size_y self.size_y = size_y self.ndv = ndv self.ndv = ndv self._ndv_threshold = ndv_threshold self._ndv_threshold = ndv_threshold self.buffer = buffer self.buffer = buffer def roi_coords_to_image_coords(self, x, y): """ Given coordinates in ROI pixel space, return the coordinates in image coordinate space. """ return self.affine((x, y))[0] @property @property def affine(self): def affine(self): """ """ This affine sets the origin of the ROI to be (0,0). This affine sets the origin of the ROI to be (0,0). """ """ return self._affine return tf.AffineTransform(translation=(self.x, self.y)) @property @property def x(self): def x(self): Loading Loading @@ -151,9 +156,8 @@ class Roi(): @property @property def center(self): def center(self): return (0,0) ie = self.image_extent #ie = self.image_extent return ((ie[1] - ie[0])-1)/2. + 0.5, ((ie[3]-ie[2])-1)/2. + 0.5 #return ((ie[1] - ie[0])-1)/2. + 0.5, ((ie[3]-ie[2])-1)/2. + 0.5 @property @property def is_valid(self): def is_valid(self): Loading