added expansion functionality to ROI

This commit is contained in:
2025-07-13 15:27:53 +02:00
parent b671e2d8dc
commit ed090be840

View File

@@ -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}')"