diff options
author | Théo de la Hogue | 2023-05-16 19:20:38 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-05-16 19:20:38 +0200 |
commit | cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6 (patch) | |
tree | a0ef672913127a619214eb23a2120dfd703b060b | |
parent | f989212bf56a45600cfa17686664bc9375749d6c (diff) | |
download | argaze-cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6.zip argaze-cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6.tar.gz argaze-cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6.tar.bz2 argaze-cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6.tar.xz |
Adding new AOIFrame class and point_spread method.
-rw-r--r-- | src/argaze/AreaOfInterest/AOIFeatures.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/argaze/AreaOfInterest/AOIFeatures.py b/src/argaze/AreaOfInterest/AOIFeatures.py index 669db72..020b050 100644 --- a/src/argaze/AreaOfInterest/AOIFeatures.py +++ b/src/argaze/AreaOfInterest/AOIFeatures.py @@ -196,6 +196,43 @@ class AreaOfInterest(numpy.ndarray): center_pixel = numpy.rint(self.center).astype(int) cv.circle(frame, center_pixel, 1, color, -1) +AOIFrameType = TypeVar('AOIFrame', bound="AOIFrame") +# Type definition for type annotation convenience + +class AOIFrame(): + """Define frame to draw into 2D AOI.""" + + def __init__(self, aoi: AreaOfInterestType, size: tuple): + """ + .. warning:: + Available for 2D AOI only.""" + + assert(aoi.dimension == 2) + + self.__rX, self.__rY = size + + # Init coordinates + self.__Sx = numpy.linspace(0., self.__rX/self.__rY, self.__rX) + self.__Sy = numpy.linspace(0., 1., self.__rY) + + # Init frame + self.__frame = numpy.zeros((self.__rY, self.__rX)) + + def point_spread(self, point: tuple, sigma: float): + """Draw gaussian point spread into frame.""" + + div = -2 * sigma**2 + + x = point[0] / self.__rY # we use rY not rX !!! + y = point[1] / self.__rY + + dX2 = (self.__Sx - x)**2 + dY2 = (self.__Sy - y)**2 + + v_dX, v_dY = numpy.array(numpy.meshgrid(dX2, dY2)).reshape(2, -1) + + return numpy.exp((v_dX + v_dY) / div).reshape(self.__rY, self.__rX) + AOISceneType = TypeVar('AOIScene', bound="AOIScene") # Type definition for type annotation convenience |