Beispiel #1
0
def semiLine(im, x0, theta, w, l, H=200, dohalf=True):
    """ Plot half-line into image 

    Args:
        im (array)
        x0 (array): starting point of semi-line
        theta (float): angle in radians
        w (float): width
        l (float): length of line segment
        H (float): intensity of line segment
        dohalf (bool): add smoothing?

    >>> im=semiLine(np.zeros( (160,240)), [60,40], theta=np.deg2rad(20), w=10, l=60)
    >>> plt.imshow(im)

    """
    thetar = -theta
    xx0, yy0 = np.meshgrid(np.arange(im.shape[1]) - x0[0], np.arange(im.shape[0]) - x0[1])
    xx0 = xx0.astype(np.float32)
    yy0 = yy0.astype(np.float32)

    xxr = math.cos(thetar) * xx0 - math.sin(thetar) * yy0
    yyr = math.sin(thetar) * xx0 + math.cos(thetar) * yy0
    yyr = pgeometry.signedmin(yyr, w / 2.)

    data = H * np.cos((np.pi / w) * yyr)
    if dohalf:
        data *= (pgeometry.smoothstep(xxr, 0, 10))

    im += data
    return im
Beispiel #2
0
def lineSegment(im, x0, x1=None, theta=None, w=2, l=12, H=200, ml=0):
    """ Plot half-line into image 

    >>> lineSegment(np.zeros( (160,240)), [60,40], [70,40], w=10, l=60)
    >>> lineSegment(np.zeros( (160,240)), [60,40], theta=np.deg2rad(20), w=10, l=60)

    """
    x0 = np.array(x0).flatten()
    if x1 is None:
        thetar = -theta
        dx = l
    else:
        x1 = np.array(x1).flatten()
        theta = x0 - x1
        theta = np.arctan2(theta[1], theta[0]) + np.pi
        thetar = -theta

        dx = np.linalg.norm(x0 - x1)

    xx0, yy0 = np.meshgrid(np.arange(im.shape[1]) - x0[0], np.arange(im.shape[0]) - x0[1])
    xx0 = xx0.astype(np.float32)
    yy0 = yy0.astype(np.float32)

    xxr = math.cos(thetar) * xx0 - math.sin(thetar) * yy0
    yyr = math.sin(thetar) * xx0 + math.cos(thetar) * yy0
    yyr = pgeometry.signedmin(yyr, w / 2.)

    data = H * np.cos((np.pi / w) * yyr) * (pgeometry.smoothstep(xxr, ml, 4)) * (1 - pgeometry.smoothstep(xxr, dx, 4))

    im += data
    return im