diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index 138c447..86c2059 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -380,7 +380,8 @@ class ROI: Example: ROI(left=10, right=20, bottom=100, top=200). - Directions assume that lower left corner of image is at (x=0, y=0). + Directions assume that lower left corner of image is at (x=0, y=0) + and y is pointing upwards, x pointing to the right. """ def __init__( @@ -457,7 +458,7 @@ class ROI: """ Returns a new ROI that is shifted by x to the left and by y pixels up. - If `inplace=True` shifts the existing ROI instead. + If `inplace=True` shifts the itself instead. """ if not inplace: return ROI(left=self.left+x, @@ -472,6 +473,26 @@ class ROI: self.top = self.top + y + def expand(self, x: float, y: float, inplace=False): + """ Returns a new ROI that is expanded in x + to the left and right, and in y to the + top and bottom. + + If `inplace=True` expands the itself instead. + """ + if not inplace: + return ROI(left=self.left - x, + right=self.right + x, + bottom = self.bottom - y, + top=self.top + y, + name=self.name) + else: + self.left = self.left - x + self.right = self.right + x + self.bottom = self.bottom - y + self.top = self.top + y + + def __repr__(self): if hasattr(self, "name"): return f"ROI(bottom={self.bottom},top={self.top},left={self.left},right={self.right},name='{self.name}')"