Пример #1
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
Пример #2
0
def iathick(f, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"):
    from ia870.iaisbinary import iaisbinary
    from ia870.iaintersec import iaintersec
    from ia870.iasupgen import iasupgen
    from ia870.iainterot import iainterot
    from ia870.iaunion import iaunion
    from ia870.iaisequal import iaisequal
    from ia870.iahomothick import iahomothick
    if Iab is None:
        Iab = iahomothick()

    DIRECTION = DIRECTION.upper()
    assert iaisbinary(f), 'f must be binary image'
    if n == -1: n = product(f.shape)
    y = f
    zero = iaintersec(f, 0)
    for i in range(n):
        aux = zero
        for t in range(0, 360, theta):
            sup = iasupgen(y, iainterot(Iab, t, DIRECTION))
            aux = iaunion(aux, sup)
            y = iaunion(y, sup)
        if iaisequal(aux, zero): break

    return y
Пример #3
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
Пример #4
0
def iacdil(f, g, b=iasecross(), n=1):
    from ia870.iaintersec import iaintersec
    from ia870.iadil import iadil
    from ia870.iaisequal import iaisequal

    y = iaintersec(f, g)
    for i in range(n):
        aux = y
        y = iaintersec(iadil(y, b), g)
        if iaisequal(y, aux): break
    return y
Пример #5
0
def iacero(f, g, b=iasecross(), n=1):
    from ia870.iaunion import iaunion
    from ia870.iaero import iaero
    from ia870.iaisequal import iaisequal

    y = iaunion(f, g)
    for i in range(n):
        aux = y
        y = iaunion(iaero(y, b), g)
        if iaisequal(y, aux): break
    return y
Пример #6
0
def iais(f1, oper, f2=None, oper1=None, f3=None):
    from ia870.iaisbinary import iaisbinary
    from ia870.iaisequal import iaisequal
    from ia870.iaislesseq import iaislesseq
    from ia870.ianeg import ianeg
    from ia870.iathreshad import iathreshad
    from ia870.iabinary import iabinary


    if f2 == None:
        oper=oper.upper();
        if   oper == 'BINARY': return iaisbinary(f1)
        elif oper == 'GRAY'  : return not iaisbinary(f1)
        else:
            assert 0,'oper should be BINARY or GRAY, was'+oper
    elif oper == '==':    y = iaisequal(f1, f2)
    elif oper == '~=':    y = not iaisequal(f1,f2)
    elif oper == '<=':    y = iaislesseq(f1,f2)
    elif oper == '>=':    y = iaislesseq(f2,f1)
    elif oper == '>':     y = iaisequal( ianeg( iathreshad(f2,f1)),iabinary(1))
    elif oper == '<':     y = iaisequal( ianeg( iathreshad(f1,f2)),iabinary(1))
    else:
        assert 0,'oper must be one of: ==, ~=, >, >=, <, <=, it was:'+oper
    if oper1 != None:
        oper1 = oper1.upper()
        if   oper1 == '==': y = y and iaisequal(f2,f3)
        elif oper1 == '~=': y = y and (not iaisequal(f2,f3))
        elif oper1 == '<=': y = y and iaislesseq(f2,f3)
        elif oper1 == '>=': y = y and iaislesseq(f3,f2)
        elif oper1 == '>':  y = y and iaisequal( ianeg( iathreshad(f3,f2)),iabinary(1))
        elif oper1 == '<':  y = y and iaisequal( ianeg( iathreshad(f2,f3)),iabinary(1))
        else:
            assert 0,'oper1 must be one of: ==, ~=, >, >=, <, <=, it was:'+oper1


    return y
Пример #7
0
def iacthin(f, g, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"):
    from ia870.iaisbinary import iaisbinary
    from ia870.iasupgen import iasupgen
    from ia870.iainterot import iainterot
    from ia870.iaunion import iaunion
    from ia870.iasubm import iasubm
    from ia870.iaisequal import iaisequal
    from ia870.iahomothin import iahomothin
    if Iab is None:
        Iab = iahomothin()

    DIRECTION = DIRECTION.upper()
    assert iaisbinary(f), 'f must be binary image'
    if n == -1: n = product(f.shape)
    y = f
    old = y
    for i in range(n):
        for t in range(0, 360, theta):
            sup = iasupgen(y, iainterot(Iab, t, DIRECTION))
            y = iaunion(iasubm(y, sup), g)
        if iaisequal(old, y): break
        old = y

    return y