コード例 #1
0
ファイル: iais.py プロジェクト: mariecpereira/IA369Z
def iais(f1, oper, f2=None, oper1=None, f3=None):
    from iaisbinary import iaisbinary
    from iaisequal import iaisequal
    from iaislesseq import iaislesseq
    from ianeg import ianeg
    from iathreshad import iathreshad
    from iabinary import iabinary


    if f2 == None:
        oper=upper(oper);
        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:
        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
コード例 #2
0
ファイル: iadil.py プロジェクト: mariecpereira/IA369Z
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
コード例 #3
0
ファイル: iaskelm.py プロジェクト: DiJei/ia870
def iaskelm(f, B=iasecross(), option="binary"):
    from iaisbinary import iaisbinary
    from ialimits import ialimits
    from iagray import iagray
    from iaintersec import iaintersec
    from iasesum import iasesum
    from iaero import iaero
    from iaisequal import iaisequal
    from iaopenth import iaopenth
    from iasedil import iasedil
    from iaunion import iaunion
    from iabinary import iabinary
    from iapad import iapad
    from iaunpad import iaunpad

    assert iaisbinary(f),'Input binary image only'
    option = upper(option)
    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
コード例 #4
0
def iathick(f, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"):
    from iaisbinary import iaisbinary
    from iaintersec import iaintersec
    from iasupgen import iasupgen
    from iainterot import iainterot
    from iaunion import iaunion
    from iaisequal import iaisequal
    from iahomothick import iahomothick
    if Iab is None:
        Iab = iahomothick()

    DIRECTION = upper(DIRECTION)
    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
コード例 #5
0
def iaskelm(f, B=iasecross(), option="binary"):
    from iaisbinary import iaisbinary
    from ialimits import ialimits
    from iagray import iagray
    from iaintersec import iaintersec
    from iasesum import iasesum
    from iaero import iaero
    from iaisequal import iaisequal
    from iaopenth import iaopenth
    from iasedil import iasedil
    from iaunion import iaunion
    from iabinary import iabinary
    from iapad import iapad
    from iaunpad import iaunpad

    assert iaisbinary(f), 'Input binary image only'
    option = upper(option)
    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
コード例 #6
0
ファイル: iathick.py プロジェクト: DiJei/ia870
def iathick(f, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"):
    from iaisbinary import iaisbinary
    from iaintersec import iaintersec
    from iasupgen import iasupgen
    from iainterot import iainterot
    from iaunion import iaunion
    from iaisequal import iaisequal
    from iahomothick import iahomothick
    if Iab is None:
        Iab = iahomothick()

    DIRECTION = upper(DIRECTION)
    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
コード例 #7
0
ファイル: iadil.py プロジェクト: 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
コード例 #8
0
ファイル: iais.py プロジェクト: ramosapf/ia870
def iais(f1, oper, f2=None, oper1=None, f3=None):
    from iaisbinary import iaisbinary
    from iaisequal import iaisequal
    from iaislesseq import iaislesseq
    from ianeg import ianeg
    from iathreshad import iathreshad
    from iabinary import iabinary

    if f2 == None:
        oper = upper(oper)
        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:
        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
コード例 #9
0
def iaopentransf(f,
                 type='OCTAGON',
                 n=65535,
                 Bc=iasecross(),
                 Buser=iasecross()):
    from iaisbinary import iaisbinary
    from iabinary import iabinary
    from iaisequal import iaisequal
    from iaopen import iaopen
    from iasesum import iasesum
    from iasedisk import iasedisk
    from iaaddm import iaaddm
    from iagray import iagray
    from iagrain import iagrain
    from ialabel import ialabel

    assert iaisbinary(f), 'Error: input image is not binary'
    type = upper(type)
    rec_flag = find(type, '-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.'
        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
コード例 #10
0
ファイル: ialastero.py プロジェクト: mariecpereira/IA369Z
def ialastero(f, B=iasecross()):
    from iaisbinary import iaisbinary
    from iadist import iadist
    from iaregmax import iaregmax

    assert iaisbinary(f), 'Can only process binary images'
    dt = iadist(f, B)
    y = iaregmax(dt, B)
    return y
コード例 #11
0
ファイル: ialastero.py プロジェクト: ramosapf/ia870
def ialastero(f, B=iasecross()):
    from iaisbinary import iaisbinary
    from iadist import iadist
    from iaregmax import iaregmax

    assert iaisbinary(f), "Can only process binary images"
    dt = iadist(f, B)
    y = iaregmax(dt, B)
    return y
コード例 #12
0
ファイル: iaopentransf.py プロジェクト: DiJei/ia870
def iaopentransf(f, type='OCTAGON', n=65535, Bc=iasecross(), Buser=iasecross()):
    from iaisbinary import iaisbinary
    from iabinary import iabinary
    from iaisequal import iaisequal
    from iaopen import iaopen
    from iasesum import iasesum
    from iasedisk import iasedisk
    from iaaddm import iaaddm
    from iagray import iagray
    from iagrain import iagrain
    from ialabel import ialabel

    assert iaisbinary(f),'Error: input image is not binary'
    type = upper(type)
    rec_flag = find(type,'-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.'
        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
コード例 #13
0
ファイル: iapatspec.py プロジェクト: mariecpereira/IA369Z
def iapatspec(f, type='OCTAGON', n=65535, Bc=None, Buser=None):
    from iaisbinary import iaisbinary
    from iaopentransf import iaopentransf
    from iahistogram import iahistogram
    from iasecross import iasecross
    if Bc is None:
        Bc = iasecross(None)
    if Buser is None:
        Buser = iasecross(None)

    assert iaisbinary(f), 'Error: input image is not binary'
    g = iaopentransf(f, type, n, Bc, Buser)
    h = iahistogram(g)
    h = h[1:]
    return h
コード例 #14
0
def iagshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None):
    from iaisbinary import iaisbinary
    from iagray import iagray
    from iaunion import iaunion
    from iaintersec import iaintersec
    from ianeg import ianeg
    from iaconcat import iaconcat

    if iaisbinary(X): X = iagray(X, 'uint8')
    r = X
    g = X
    b = X
    if X1 is not None:  # red 1 0 0
        assert iaisbinary(X1), 'X1 must be binary overlay'
        x1 = iagray(X1, 'uint8')
        r = iaunion(r, x1)
        g = iaintersec(g, ianeg(x1))
        b = iaintersec(b, ianeg(x1))
    if X2 is not None:  # green 0 1 0
        assert iaisbinary(X2), 'X2 must be binary overlay'
        x2 = iagray(X2, 'uint8')
        r = iaintersec(r, ianeg(x2))
        g = iaunion(g, x2)
        b = iaintersec(b, ianeg(x2))
    if X3 is not None:  # blue 0 0 1
        assert iaisbinary(X3), 'X3 must be binary overlay'
        x3 = iagray(X3, 'uint8')
        r = iaintersec(r, ianeg(x3))
        g = iaintersec(g, ianeg(x3))
        b = iaunion(b, x3)
    if X4 is not None:  # magenta 1 0 1
        assert iaisbinary(X4), 'X4 must be binary overlay'
        x4 = iagray(X4, 'uint8')
        r = iaunion(r, x4)
        g = iaintersec(g, ianeg(x4))
        b = iaunion(b, x4)
    if X5 is not None:  # yellow 1 1 0
        assert iaisbinary(X5), 'X5 must be binary overlay'
        x5 = iagray(X5, 'uint8')
        r = iaunion(r, x5)
        g = iaunion(g, x5)
        b = iaintersec(b, ianeg(x5))
    if X6 is not None:  # cyan 0 1 1
        assert iaisbinary(X6), 'X6 must be binary overlay'
        x6 = iagray(X6, 'uint8')
        r = iaintersec(r, ianeg(x6))
        g = iaunion(g, x6)
        b = iaunion(b, x6)
    return iaconcat('d', r, g, b)
    return Y
コード例 #15
0
def iainpos(f, g, bc=iasecross()):
    from iaisbinary import iaisbinary
    from iagray import iagray
    from ianeg import ianeg
    from iadatatype import iadatatype
    from ialimits import ialimits
    from iasuprec import iasuprec
    from iaintersec import iaintersec
    from iaunion import iaunion

    assert iaisbinary(f), 'First parameter must be binary image'
    fg = iagray(ianeg(f), iadatatype(g))
    k1 = ialimits(g)[1] - 1
    y = iasuprec(fg, iaintersec(iaunion(g, 1), k1, fg), bc)

    return y
コード例 #16
0
ファイル: iainpos.py プロジェクト: DiJei/ia870
def iainpos(f, g, bc=iasecross()):
    from iaisbinary import iaisbinary
    from iagray import iagray
    from ianeg import ianeg
    from iadatatype import iadatatype
    from ialimits import ialimits
    from iasuprec import iasuprec
    from iaintersec import iaintersec
    from iaunion import iaunion

    assert iaisbinary(f),'First parameter must be binary image'
    fg = iagray( ianeg(f), iadatatype(g))
    k1 = ialimits(g)[1] - 1
    y = iasuprec(fg, iaintersec( iaunion(g, 1), k1, fg), bc)

    return y
コード例 #17
0
ファイル: iapatspec.py プロジェクト: ramosapf/ia870
def iapatspec(f, type="OCTAGON", n=65535, Bc=None, Buser=None):
    from iaisbinary import iaisbinary
    from iaopentransf import iaopentransf
    from iahistogram import iahistogram
    from iasecross import iasecross

    if Bc is None:
        Bc = iasecross(None)
    if Buser is None:
        Buser = iasecross(None)

    assert iaisbinary(f), "Error: input image is not binary"
    g = iaopentransf(f, type, n, Bc, Buser)
    h = iahistogram(g)
    h = h[1:]
    return h
コード例 #18
0
ファイル: iagshow.py プロジェクト: DiJei/ia870
def iagshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None):
    from iaisbinary import iaisbinary
    from iagray import iagray
    from iaunion import iaunion
    from iaintersec import iaintersec
    from ianeg import ianeg
    from iaconcat import iaconcat

    if iaisbinary(X): X = iagray(X,'uint8')
    r = X
    g = X
    b = X
    if X1 is not None: # red 1 0 0
      assert iaisbinary(X1),'X1 must be binary overlay'
      x1 = iagray(X1,'uint8')
      r = iaunion(r,x1)
      g = iaintersec(g,ianeg(x1))
      b = iaintersec(b,ianeg(x1))
    if X2 is not None: # green 0 1 0
      assert iaisbinary(X2),'X2 must be binary overlay'
      x2 = iagray(X2,'uint8')
      r = iaintersec(r,ianeg(x2))
      g = iaunion(g,x2)
      b = iaintersec(b,ianeg(x2))
    if X3 is not None: # blue 0 0 1
      assert iaisbinary(X3),'X3 must be binary overlay'
      x3 = iagray(X3,'uint8')
      r = iaintersec(r,ianeg(x3))
      g = iaintersec(g,ianeg(x3))
      b = iaunion(b,x3)
    if X4 is not None: # magenta 1 0 1
      assert iaisbinary(X4),'X4 must be binary overlay'
      x4 = iagray(X4,'uint8')
      r = iaunion(r,x4)
      g = iaintersec(g,ianeg(x4))
      b = iaunion(b,x4)
    if X5 is not None: # yellow 1 1 0
      assert iaisbinary(X5),'X5 must be binary overlay'
      x5 = iagray(X5,'uint8')
      r = iaunion(r,x5)
      g = iaunion(g,x5)
      b = iaintersec(b,ianeg(x5))
    if X6 is not None: # cyan 0 1 1
      assert iaisbinary(X6),'X6 must be binary overlay'
      x6 = iagray(X6,'uint8')
      r = iaintersec(r,ianeg(x6))
      g = iaunion(g,x6)
      b = iaunion(b,x6)
    return iaconcat('d',r,g,b)
    return Y
コード例 #19
0
def iacthin(f, g, Iab=None, n=-1, theta=45, DIRECTION="CLOCKWISE"):
    from iaisbinary import iaisbinary
    from iasupgen import iasupgen
    from iainterot import iainterot
    from iaunion import iaunion
    from iasubm import iasubm
    from iaisequal import iaisequal
    from iahomothin import iahomothin
    if Iab is None:
        Iab = iahomothin()

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