From cea1b65d8e3ba9827ffb4ed1fc4e89a8a3b57dd6 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Tue, 16 May 2023 19:20:38 +0200 Subject: Adding new AOIFrame class and point_spread method. --- src/argaze/AreaOfInterest/AOIFeatures.py | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src') 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 -- cgit v1.1