Skip to content

Commit

Permalink
Fix edge cases affecting synthetic/small datasets
Browse files Browse the repository at this point in the history
* Skip LayerAligner.register padding=0 assert when error is inf or
  insersection shape is <=1 in some dimension
* Skip LayerAligner.register_angle when intersection shape is <=1 in some
  dimension (increased from 0)
* Remove step where LayerAligner intersection size is rounded to a multiple
  of 32 pixels
  • Loading branch information
jmuhlich committed Jul 11, 2024
1 parent cae27cf commit 59927fb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ashlar/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,14 +978,18 @@ def register(self, t):
# Add back in the fractional position difference that overlap() loses.
# TODO How does rotation affect this?
shift = tuple(shift + its.offset_diff_frac)
# We don't use padding and thus can skip the math to account for it.
assert (its.padding == 0).all(), "Unexpected non-zero padding"
# We don't use padding and thus can skip the math to account for it, but
# we will assert this just to make sure.
if error < np.inf and all(its.shape > 1):
# Skip assertion if error is infinite, indicating a degenerate
# Intersection that won't be usable anyway.
assert (its.padding == 0).all(), "Unexpected non-zero padding"
return shift, error

def register_angle(self, t):
"""Return relative rotation angle between images."""
its, ref_img, img = self.overlap(t)
if np.any(np.array(its.shape) == 0):
if np.any(np.array(its.shape) <= 1):
return np.nan
angle = utils.register_angle(ref_img, img, self.filter_sigma)
return angle
Expand Down Expand Up @@ -1018,7 +1022,6 @@ def intersection(self, t):
corners1 = np.vstack([center_a, center_b]) - self.reader.metadata.size / 2
corners2 = corners1 + self.reader.metadata.size
its = Intersection(corners1, corners2)
its.shape = its.shape // 32 * 32
return its

def overlap(self, t):
Expand Down

0 comments on commit 59927fb

Please sign in to comment.