Example #1
0
File: iadil.py Project: DiJei/ia870
def iadil(f, b=None):
    from iamat2set import iamat2set
    from ialimits import ialimits
    from iaisbinary import iaisbinary
    from iaintersec import iaintersec
    from iagray import iagray
    from iaadd4dil import iaadd4dil
    from iasecross import iasecross

    if b is None: b = iasecross()

    if len(f.shape) == 1: f = f[newaxis,:]
    h,w = f.shape
    x,v = iamat2set(b)
    if len(x)==0:
        y = (ones((h,w)) * ialimits(f)[0]).astype(f.dtype)
    else:
        if iaisbinary(v):
            v = iaintersec( iagray(v,'int32'),0)
        mh,mw = max(abs(x)[:,0]),max(abs(x)[:,1])
        y = (ones((h+2*mh,w+2*mw)) * ialimits(f)[0]).astype(f.dtype)
        for i in range(x.shape[0]):
            if v[i] > -2147483647:
                y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w] = maximum(
                    y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w], iaadd4dil(f,v[i]))
        y = y[mh:mh+h, mw:mw+w]

    return y
Example #2
0
def iadil(f, b=None):
    from iamat2set import iamat2set
    from ialimits import ialimits
    from iaisbinary import iaisbinary
    from iaintersec import iaintersec
    from iagray import iagray
    from iaadd4dil import iaadd4dil
    from iasecross import iasecross

    if b is None: b = iasecross()

    if len(f.shape) == 1: f = f[newaxis, :]
    h, w = f.shape
    x, v = iamat2set(b)
    if len(x) == 0:
        y = (ones((h, w)) * ialimits(f)[0]).astype(f.dtype)
    else:
        if iaisbinary(v):
            v = iaintersec(iagray(v, 'int32'), 0)
        mh, mw = max(abs(x)[:, 0]), max(abs(x)[:, 1])
        y = (ones((h + 2 * mh, w + 2 * mw)) * ialimits(f)[0]).astype(f.dtype)
        for i in range(x.shape[0]):
            if v[i] > -2147483647:
                y[mh + x[i, 0]:mh + x[i, 0] + h,
                  mw + x[i, 1]:mw + x[i, 1] + w] = maximum(
                      y[mh + x[i, 0]:mh + x[i, 0] + h,
                        mw + x[i, 1]:mw + x[i, 1] + w], iaadd4dil(f, v[i]))
        y = y[mh:mh + h, mw:mw + w]

    return y
Example #3
0
def iaunpad(f, B=iasecross()):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i,v=iamat2set( iaseshow(B));
    mni=minimum.reduce(i)
    mxi=maximum.reduce(i)
    g = f[-mni[0]:f.shape[0]-mxi[0], -mni[1]:f.shape[1]-mxi[1]]

    return g
Example #4
0
def iasetrans(Bi, t):
    from iamat2set import iamat2set
    from iaset2mat import iaset2mat


    x,v=iamat2set(Bi)
    Bo = iaset2mat((x+t,v))
    Bo = Bo.astype(Bi.dtype)

    return Bo
Example #5
0
def iaunpad(f, B=iasecross()):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i, v = iamat2set(iaseshow(B))
    mni = minimum.reduce(i)
    mxi = maximum.reduce(i)
    g = f[-mni[0]:f.shape[0] - mxi[0], -mni[1]:f.shape[1] - mxi[1]]

    return g
Example #6
0
def iapad(f, B=iasecross(), value=0):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i, v = iamat2set(iaseshow(B))
    mni = i.min(axis=0)
    mxi = i.max(axis=0)
    f = asarray(f)
    if size(f.shape) == 1: f = f[newaxis, :]
    g = (value * ones(array(f.shape) + mxi - mni)).astype(f.dtype)
    g[-mni[0]:g.shape[0] - mxi[0], -mni[1]:g.shape[1] - mxi[1]] = f

    return g
Example #7
0
File: iapad.py Project: DiJei/ia870
def iapad(f, B=iasecross(), value=0):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i,v=iamat2set( iaseshow(B));
    mni=i.min(axis=0)
    mxi=i.max(axis=0)
    f = asarray(f)
    if size(f.shape) == 1: f = f[newaxis,:]
    g = (value * ones(array(f.shape)+mxi-mni)).astype(f.dtype)
    g[-mni[0]:g.shape[0]-mxi[0], -mni[1]:g.shape[1]-mxi[1]] = f

    return g
Example #8
0
def iaserot(B, theta=45, DIRECTION="CLOCKWISE"):
    from iamat2set import iamat2set
    from iabinary import iabinary
    from iaset2mat import iaset2mat

    DIRECTION = upper(DIRECTION)
    if DIRECTION == "ANTI-CLOCKWISE":
        theta = -theta
    SA = iamat2set(B)
    theta = pi * theta / 180
    (y, v) = SA
    if len(y) == 0: return iabinary([0])
    x0 = y[:, 1] * cos(theta) - y[:, 0] * sin(theta)
    x1 = y[:, 1] * sin(theta) + y[:, 0] * cos(theta)
    x0 = int32((x0 + 0.5) * (x0 >= 0) + (x0 - 0.5) * (x0 < 0))
    x1 = int32((x1 + 0.5) * (x1 >= 0) + (x1 - 0.5) * (x1 < 0))
    x = transpose(array([transpose(x1), transpose(x0)]))
    BROT = iaset2mat((x, v))

    return BROT
Example #9
0
def iaserot(B, theta=45, DIRECTION="CLOCKWISE"):
    from iamat2set import iamat2set
    from iabinary import iabinary
    from iaset2mat import iaset2mat


    DIRECTION = upper(DIRECTION)
    if DIRECTION == "ANTI-CLOCKWISE":
       theta = -theta
    SA = iamat2set(B)
    theta = pi * theta/180
    (y,v)=SA
    if len(y)==0: return iabinary([0])
    x0 = y[:,1] * cos(theta) - y[:,0] * sin(theta)
    x1 = y[:,1] * sin(theta) + y[:,0] * cos(theta)
    x0 = int32((x0 +0.5)*(x0>=0) + (x0-0.5)*(x0<0))
    x1 = int32((x1 +0.5)*(x1>=0) + (x1-0.5)*(x1<0))
    x = transpose(array([transpose(x1),transpose(x0)]))
    BROT = iaset2mat((x,v))

    return BROT