Beispiel #1
0
def iaasf(f, SEQ="OC", b=None, n=1):
    from ia870.iasesum import iasesum
    from ia870.iaopen import iaopen
    from ia870.iaclose import iaclose
    from ia870.iasecross import iasecross
    if b is None:
        b = iasecross(None)

    SEQ = SEQ.upper()
    y = f
    if SEQ == 'OC':
        for i in range(1, n + 1):
            nb = iasesum(b, i)
            y = iaopen(iaclose(y, nb), nb)
    elif SEQ == 'CO':
        for i in range(1, n + 1):
            nb = iasesum(b, i)
            y = iaclose(iaopen(y, nb), nb)
    elif SEQ == 'OCO':
        for i in range(1, n + 1):
            nb = iasesum(b, i)
            y = iaopen(iaclose(iaopen(y, nb), nb), nb)
    elif SEQ == 'COC':
        for i in range(1, n + 1):
            nb = iasesum(b, i)
            y = iaclose(iaopen(iaclose(y, nb), nb), nb)

    return y
Beispiel #2
0
def iaskelm(f, B=iasecross(), option="binary"):
    from ia870.iaisbinary import iaisbinary
    from ia870.ialimits import ialimits
    from ia870.iagray import iagray
    from ia870.iaintersec import iaintersec
    from ia870.iasesum import iasesum
    from ia870.iaero import iaero
    from ia870.iaisequal import iaisequal
    from ia870.iaopenth import iaopenth
    from ia870.iasedil import iasedil
    from ia870.iaunion import iaunion
    from ia870.iabinary import iabinary
    from ia870.iapad import iapad
    from ia870.iaunpad import iaunpad

    assert iaisbinary(f),'Input binary image only'
    option = option.upper()
    f = iapad(f,B)
    print(f)
    k1,k2 = ialimits(f)
    y = iagray( iaintersec(f, k1),'uint16')
    iszero = asarray(y)
    nb = iasesum(B,0)
    for r in range(1,65535):
        ero = iaero( f, nb)
        if iaisequal(ero, iszero): break
        f1 = iaopenth( ero, B)
        nb = iasedil(nb, B)
        y = iaunion(y, iagray(f1,'uint16',r))
    if option == 'BINARY':
        y = iabinary(y)
    y = iaunpad(y,B)
    return y
Beispiel #3
0
def iacbisector(f, B, n):
    from ia870.iaintersec import iaintersec
    from ia870.iasesum import iasesum
    from ia870.iaero import iaero
    from ia870.iacdil import iacdil
    from ia870.iasubm import iasubm
    from ia870.iaunion import iaunion

    y = iaintersec(f, 0)
    for i in range(n):
        nb = iasesum(B, i)
        nbp = iasesum(B, i + 1)
        f1 = iaero(f, nbp)
        f2 = iacdil(f1, f, B, n)
        f3 = iasubm(iaero(f, nb), f2)
        y = iaunion(y, f3)
    return y
Beispiel #4
0
def iaopentransf(f, type='OCTAGON', n=65535, Bc=iasecross(), Buser=iasecross()):
    from ia870.iaisbinary import iaisbinary
    from ia870.iabinary import iabinary
    from ia870.iaisequal import iaisequal
    from ia870.iaopen import iaopen
    from ia870.iasesum import iasesum
    from ia870.iasedisk import iasedisk
    from ia870.iaaddm import iaaddm
    from ia870.iagray import iagray
    from ia870.iagrain import iagrain
    from ia870.ialabel import ialabel

    assert iaisbinary(f),'Error: input image is not binary'
    type = type.upper()
    rec_flag = (type).find('-REC')
    if rec_flag != -1:
        type = type[:rec_flag] # remove the -rec suffix
    flag = not ((type == 'OCTAGON')  or
                (type == 'CHESSBOARD') or
                (type == 'CITY-BLOCK'))
    if not flag:
        n  = min(n,min(f.shape))
    elif  type == 'LINEAR-H':
        se = iabinary([1, 1, 1])
        n  = min(n,f.shape[1])
    elif  type =='LINEAR-V':
        se = iabinary([[1],[1],[1]])
        n  = min(n,f.shape[0])
    elif  type == 'LINEAR-45R':
        se = iabinary([[0, 0, 1],[0, 1, 0],[1, 0, 0]])
        n  = min(n,min(f.shape))
    elif  type == 'LINEAR-45L':
        se = iabinary([[1, 0, 0],[0, 1, 0],[0, 0, 1]])
        n  = min(n,min(f.shape))
    elif  type == 'USER':
        se = Buser
        n  = min(n,min(f.shape))
    else:
        #print('Error: only accepts OCTAGON, CHESSBOARD, CITY-BLOCK, LINEAR-H, LINEAR-V, LINEAR-45R, LINEAR-45L, or USER as type, or with suffix -REC.')
        print('Error')
        return []
    k = 0
    y = uint16(zeros(f.shape))
    a = iabinary([1])
    z = iabinary([0])
    while not ( iaisequal(a,z) or (k>=n)):
        print('processing r=',k)
        if flag:
            a = iaopen(f,iasesum(se,k))
        else:
            a = iaopen(f,iasedisk(k,'2D',type))
        y = iaaddm(y, iagray(a,'uint16',1))
        k = k+1
    if rec_flag != -1:
        y = iagrain( ialabel(f,Bc),y,'max')

    return y
Beispiel #5
0
def iaasfrec(f, SEQ="OC", b=iasecross(), bc=iasecross(), n=1):
    from ia870.iasesum import iasesum
    from ia870.iacloserec import iacloserec
    from ia870.iaopenrec import iaopenrec

    SEQ = SEQ.upper()
    y = f
    if SEQ == 'OC':
        for i in range(1,n+1):
            nb = iasesum(b,i)
            y = iacloserec(y,nb,bc)
            y = iaopenrec(y,nb,bc)
    elif SEQ == 'CO':
        for i in range(1,n+1):
            nb = iasesum(b,i)
            y = iaopenrec(y,nb,bc)
            y = iacloserec(y,nb,bc)
    else:
        assert 0,'Only accepts OC or CO for SEQ parameter'

    return y
Beispiel #6
0
def iasecross(r=1):
    from ia870.iasesum import iasesum
    from ia870.iabinary import iabinary

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