Example #1
0
def iaseshow(B, option="NORMAL"):
    from ia870 import iaisbinary, iaintersec, iagray, iabinary
    from ia870 import iasedil, iaero, iabshow

    option = upper(option)
    if option == "NON-FLAT":
        y = array([0], int32)
        if iaisbinary(B):
            B = iaintersec(iagray(B, "int32"), 0)
    elif option == "NORMAL":
        if iaisbinary(B):
            y = iabinary([1])
        else:
            y = array([0], int32)
    elif option == "EXPAND":
        assert iaisbinary(B), "This option is only available with flat SE"
        y = iasedil(iabinary([1]), B)
        b1 = iabinary(y >= 0)
        b0 = b1 < 0
        b0[shape(b0)[0] / 2, shape(b0)[1] / 2] = 1
        y = iabshow(b1, y, b0)
        return y
    else:
        print "iaseshow: not a valid flag: NORMAL, EXPAND or NON-FLAT"

    y = iasedil(y, B)
    return y
Example #2
0
def iaseshow(B, option="NORMAL"):
    from ia870 import iaisbinary, iaintersec, iagray, iabinary
    from ia870 import iasedil, iaero, iabshow

    option = upper(option)
    if option == 'NON-FLAT':
        y = array([0], int32)
        if iaisbinary(B):
            B = iaintersec(iagray(B, 'int32'), 0)
    elif option == 'NORMAL':
        if iaisbinary(B): y = iabinary([1])
        else:
            y = array([0], int32)
    elif option == 'EXPAND':
        assert iaisbinary(B), 'This option is only available with flat SE'
        y = iasedil(iabinary([1]), B)
        b1 = iabinary(y >= 0)
        b0 = b1 < 0
        b0[shape(b0)[0] / 2, shape(b0)[1] / 2] = 1
        y = iabshow(b1, y, b0)
        return y
    else:
        print('iaseshow: not a valid flag: NORMAL, EXPAND or NON-FLAT')

    y = iasedil(y, B)
    return y
Example #3
0
def iasedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0):
    from ia870 import iabinary, iasecross, iasedil, iasesum
    from ia870 import iasebox, iaseintersec, iagray

    METRIC = METRIC.upper()
    FLAT = FLAT.upper()
    assert DIM == '2D', 'Supports only 2D structuring elements'
    if FLAT == 'FLAT': y = iabinary([1])
    else: y = int32([h])
    if r == 0: return y
    if METRIC == 'CITY-BLOCK':
        if FLAT == 'FLAT':
            b = iasecross(1)
        else:
            b = int32([[-2147483647, 0, -2147483647], [0, 1, 0],
                       [-2147483647, 0, -2147483647]])
        return iasedil(y, iasesum(b, r))
    elif METRIC == 'CHESSBOARD':
        if FLAT == 'FLAT':
            b = iasebox(1)
        else:
            b = int32([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
        return iasedil(y, iasesum(b, r))
    elif METRIC == 'OCTAGON':
        if FLAT == 'FLAT':
            b1, b2 = iasebox(1), iasecross(1)
        else:
            b1 = int32([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
            b2 = int32([[-2147483647, 0, -2147483647], [0, 1, 0],
                        [-2147483647, 0, -2147483647]])
        if r == 1: return b1
        else:
            return iasedil(iasedil(y, iasesum(b1, r // 2)),
                           iasesum(b2, (r + 1) // 2))
    elif METRIC == 'EUCLIDEAN':
        v = arange(-r, r + 1)
        x = resize(v, (len(v), len(v)))
        y = transpose(x)
        Be = iabinary(sqrt(x * x + y * y) <= (r + 0.5))
        if FLAT == 'FLAT':
            return Be
        be = h + int32(
            sqrt(maximum((r + 0.5) * (r + 0.5) - (x * x) - (y * y), 0)))
        be = iaintersec(iagray(Be, 'int32'), be)
        return be
    else:
        assert 0, 'Non valid metric'

    return B
Example #4
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
Example #5
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
Example #6
0
def iawatershed(f, Bc=iasecross(), option='LINES'):
    from ipdp import se2offset

    offset = se2offset(Bc)
    w = connectedComponents(f, offset)
    if option == 'LINES':
        w = iasubm(w, iaero(w))
        w = iabinary(w)
    return w
Example #7
0
def iawatershed(f, Bc=iasecross(), option='LINES'):
    from ipdp import se2offset

    offset = se2offset(Bc)
    w = connectedComponents(f, offset)
    if option == 'LINES':
        w = iasubm(w, iaero(w))
        w = iabinary(w)
    return w
Example #8
0
def iasesum(B, N=1):
    from ia870 import iaisbinary, iabinary, iasedil

    if N==0:
        if iaisbinary(B): return iabinary([1])
        else:             return array([0],int32) # identity
    NB = B
    for i in range(N-1):
        NB = iasedil(NB,B)
    return NB
Example #9
0
def iasesum(B, N=1):
    from ia870 import iaisbinary, iabinary, iasedil

    if N == 0:
        if iaisbinary(B): return iabinary([1])
        else: return array([0], int32)  # identity
    NB = B
    for i in range(N - 1):
        NB = iasedil(NB, B)
    return NB
Example #10
0
def iacwatershed(f, g, Bc=iasecross(), option='LINES'):
    from ia870.ipdp import se2offset

    if iaisbinary(g):
        g = ialabel(g, Bc)
    offset = se2offset(Bc)
    w = ift_m(f, offset, g)
    if option == 'LINES':
        w = iasubm(w, iaero(w))
        w = iabinary(w)
    return w
Example #11
0
def iacwatershed(f, g, Bc=iasecross(), option='LINES'):
    from ipdp import se2offset

    if iaisbinary(g):
        g = ialabel(g, Bc)
    offset = se2offset(Bc)
    w = ift_m(f, offset, g)
    if option == 'LINES':
        w = iasubm(w, iaero(w))
        w = iabinary(w)
    return w
Example #12
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
Example #13
0
def iasebox(r=1):
    from ia870 import iasesum, iabinary

    B = iasesum(iabinary([[1, 1, 1], [1, 1, 1], [1, 1, 1]]), r)

    return B