コード例 #1
0
def iasedil(B1, B2):
    from ia870 import ialimits, iagray, iabinary, iaisbinary, iamat2set, iaadd4dil, iasetrans, iaseunion

    assert (iaisbinary(B1) or (B1.dtype == int32) or (B1.dtype == int64) or (B1.dtype == float64)) and \
           (iaisbinary(B2) or (B2.dtype == int32) or (B2.dtype == int64) or (B2.dtype == float64)), \
           'iasedil: s.e. must be binary, int32, int64 or float64'
    if len(B1.shape) == 1: B1 = B1[newaxis, :]
    if len(B2.shape) == 1: B2 = B2[newaxis, :]
    if B1.dtype == 'bool' and B2.dtype == 'bool':
        Bo = iabinary([0])
    else:
        Bo = array(ialimits(B1)[0]).reshape(1)
        if iaisbinary(B1):
            Bo = array(ialimits(B2)[0]).reshape(1)
            B1 = iagray(B1, B2.dtype, 0)
        if iaisbinary(B2):
            Bo = array(ialimits(B1)[0]).reshape(1)
            B2 = iagray(B2, B1.dtype, 0)
    x, v = iamat2set(B2)
    if len(x):
        for i in range(x.shape[0]):
            s = iaadd4dil(B1, v[i])
            st = iasetrans(s, x[i])
            Bo = iaseunion(Bo, st)
    return Bo
コード例 #2
0
def iadil(f, b=None):
    from ia870 import iamat2set, ialimits, iaisbinary
    from ia870 import iaintersec, iagray, iaadd4dil, 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
コード例 #3
0
def iaseintersec(B1, B2):
    from ialimits import ialimits
    from ia870 import iamat2set, iaset2mat

    assert B1.dtype == B2.dtype, \
      'iaseintersec: Cannot have different datatypes: \
      %s and %s'                 % (str(B1.dtype), str(B2.dtype))
    type1 = B1.dtype
    #if len(B1) == 0: return B2
    if len(B1.shape) == 1: B1 = B1[newaxis, :]
    if len(B2.shape) == 1: B2 = B2[newaxis, :]
    if B1.shape != B2.shape:
        inf = ialimits(B1)[0]
        h1, w1 = B1.shape
        h2, w2 = B2.shape
        H, W = max(h1, h2), max(w1, w2)
        Hc, Wc = (H - 1) / 2, (W - 1) / 2  # center
        BB1, BB2 = asarray(B1), asarray(B2)
        B1, B2 = inf * ones((H, W)), inf * ones((H, W))
        dh1s, dh1e = (h1 - 1) / 2, (h1 - 1) / 2 + (
            h1 + 1) % 2  # deal with even and odd dimensions
        dw1s, dw1e = (w1 - 1) / 2, (w1 - 1) / 2 + (w1 + 1) % 2
        dh2s, dh2e = (h2 - 1) / 2, (h2 - 1) / 2 + (h2 + 1) % 2
        dw2s, dw2e = (w2 - 1) / 2, (w2 - 1) / 2 + (w2 + 1) % 2
        B1[Hc - dh1s:Hc + dh1e + 1, Wc - dw1s:Wc + dw1e + 1] = BB1
        B2[Hc - dh2s:Hc + dh2e + 1, Wc - dw2s:Wc + dw2e + 1] = BB2
    B = minimum(B1, B2).astype(type1)
    i, v = iamat2set(B)
    B = iaset2mat((i, v))
    return B
コード例 #4
0
ファイル: iasedil.py プロジェクト: DiJei/ia870
def iasedil(B1, B2):
    from ia870 import ialimits, iagray, iabinary, iaisbinary, iamat2set, iaadd4dil, iasetrans, iaseunion

    assert (iaisbinary(B1) or (B1.dtype == int32) or (B1.dtype == int64) or (B1.dtype == float64)) and \
           (iaisbinary(B2) or (B2.dtype == int32) or (B2.dtype == int64) or (B2.dtype == float64)), \
           'iasedil: s.e. must be binary, int32, int64 or float64'
    if len(B1.shape) == 1: B1 = B1[newaxis,:]
    if len(B2.shape) == 1: B2 = B2[newaxis,:]
    if B1.dtype=='bool' and B2.dtype == 'bool':
       Bo = iabinary([0])
    else:
       Bo = array(ialimits(B1)[0]).reshape(1)
       if iaisbinary(B1):
          Bo = array(ialimits(B2)[0]).reshape(1)
          B1 = iagray(B1,B2.dtype,0)
       if iaisbinary(B2):
          Bo = array(ialimits(B1)[0]).reshape(1)
          B2 = iagray(B2,B1.dtype,0)
    x,v = iamat2set(B2)
    if len(x):
        for i in range(x.shape[0]):
            s = iaadd4dil(B1,v[i])
            st= iasetrans(s,x[i])
            Bo = iaseunion(Bo,st)
    return Bo
コード例 #5
0
ファイル: iaseintersec.py プロジェクト: DiJei/ia870
def iaseintersec(B1, B2):
    from ialimits import ialimits
    from ia870 import iamat2set, iaset2mat

    assert B1.dtype == B2.dtype, \
      'iaseintersec: Cannot have different datatypes: \
      %s and %s' % (str(B1.dtype), str(B2.dtype))
    type1 = B1.dtype
    #if len(B1) == 0: return B2
    if len(B1.shape) == 1: B1 = B1[newaxis,:]
    if len(B2.shape) == 1: B2 = B2[newaxis,:]
    if B1.shape <> B2.shape:
        inf = ialimits(B1)[0]
        h1,w1 = B1.shape
        h2,w2 = B2.shape
        H,W = max(h1,h2),max(w1,w2)
        Hc,Wc = (H-1)/2,(W-1)/2    # center
        BB1,BB2 = asarray(B1),asarray(B2)
        B1, B2  = inf * ones((H,W)), inf *ones((H,W))
        dh1s , dh1e = (h1-1)/2 , (h1-1)/2 + (h1+1)%2 # deal with even and odd dimensions
        dw1s , dw1e = (w1-1)/2 , (w1-1)/2 + (w1+1)%2
        dh2s , dh2e = (h2-1)/2 , (h2-1)/2 + (h2+1)%2
        dw2s , dw2e = (w2-1)/2 , (w2-1)/2 + (w2+1)%2
        B1[ Hc-dh1s : Hc+dh1e+1  ,  Wc-dw1s : Wc+dw1e+1 ] = BB1
        B2[ Hc-dh2s : Hc+dh2e+1  ,  Wc-dw2s : Wc+dw2e+1 ] = BB2
    B = minimum(B1,B2).astype(type1)
    i,v = iamat2set(B)
    B = iaset2mat((i,v))
    return B
コード例 #6
0
def iasetrans(Bi, t):
    from ia870 import iamat2set
    from ia870 import iaset2mat


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

    return Bo
コード例 #7
0
def iaserot(B, theta=45, DIRECTION="CLOCKWISE"):
    from ia870 import iamat2set, iabinary, iaset2mat

    DIRECTION = DIRECTION.upper()
    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