예제 #1
0
파일: iadist.py 프로젝트: ramosapf/ia870
def iadist(f, Bc=iasecross(), METRIC=None):
    from iagray import iagray
    from iaintersec import iaintersec
    from iaisequal import iaisequal
    from iaero import iaero
    from iasebox import iasebox

    if METRIC is not None:
        METRIC = upper(METRIC)
    f = iagray(f, "uint16")
    y = iaintersec(f, 0)
    if (METRIC == "EUCLIDEAN") or (METRIC == "EUC2"):
        f = int32(f)
        b = int32(zeros((3, 3)))
        i = 1
        while any(f != y):
            a4, a2 = -4 * i + 2, -2 * i + 1
            b = int32([[a4, a2, a4], [a2, 0, a2], [a4, a2, a4]])
            y = f
            i = i + 1
            f = iaero(f, b)
        if METRIC == "EUCLIDEAN":
            y = uint16(sqrt(f) + 0.5)
    else:
        if iaisequal(Bc, iasecross()):
            b = int32([[-2147483647, -1, -2147483647], [-1, 0, -1], [-2147483647, -1, -2147483647]])
        elif iaisequal(Bc, iasebox()):
            b = int32([[-1, -1, -1], [-1, 0, -1], [-1, -1, -1]])
        else:
            b = Bc
        while any(f != y):
            y = f
            f = iaero(f, b)
    return y
예제 #2
0
def iadist(f, Bc=iasecross(), METRIC=None):
    from iagray import iagray
    from iaintersec import iaintersec
    from iaisequal import iaisequal
    from iaero import iaero
    from iasebox import iasebox

    if METRIC is not None: METRIC = upper(METRIC)
    f = iagray(f, 'uint16')
    y = iaintersec(f, 0)
    if (METRIC == 'EUCLIDEAN') or (METRIC == 'EUC2'):
        f = int32(f)
        b = int32(zeros((3, 3)))
        i = 1
        while any(f != y):
            a4, a2 = -4 * i + 2, -2 * i + 1
            b = int32([[a4, a2, a4], [a2, 0, a2], [a4, a2, a4]])
            y = f
            i = i + 1
            f = iaero(f, b)
        if METRIC == 'EUCLIDEAN':
            y = uint16(sqrt(f) + 0.5)
    else:
        if iaisequal(Bc, iasecross()):
            b = int32([[-2147483647, -1, -2147483647], [-1, 0, -1],
                       [-2147483647, -1, -2147483647]])
        elif iaisequal(Bc, iasebox()):
            b = int32([[-1, -1, -1], [-1, 0, -1], [-1, -1, -1]])
        else:
            b = Bc
        while any(f != y):
            y = f
            f = iaero(f, b)
    return y
예제 #3
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
예제 #4
0
파일: iasedisk.py 프로젝트: DiJei/ia870
def iasedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0):
    from iabinary import iabinary
    from iasecross import iasecross
    from iasedil import iasedil
    from iasesum import iasesum
    from iasebox import iasebox
    from iaintersec import iaintersec
    from iagray import iagray

    METRIC = upper(METRIC)
    FLAT   = upper(FLAT)
    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
예제 #5
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
예제 #6
0
def iagradm(f, Bdil=None, Bero=None):
    from iasubm import iasubm
    from iadil import iadil
    from iaero import iaero
    from iasecross import iasecross
    if Bdil is None: Bdil = iasecross()
    if Bero is None: Bero = iasecross()

    y = iasubm( iadil(f,Bdil),iaero(f,Bero))
    return y
예제 #7
0
def iasedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0):
    from iabinary import iabinary
    from iasecross import iasecross
    from iasedil import iasedil
    from iasesum import iasesum
    from iasebox import iasebox
    from iaintersec import iaintersec
    from iagray import 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
예제 #8
0
def iaopenrecth(f, bero=None, bc=None):
    from iasubm import iasubm
    from iaopenrec import iaopenrec
    from iasecross import iasecross
    if bero is None:
        bero = iasecross()
    if bc is None:
        bc = iasecross()

    y = iasubm(f, iaopenrec( f, bero, bc))

    return y
예제 #9
0
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
예제 #10
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
예제 #11
0
def iahmin(f, h=1, Bc=iasecross()):
    from iaaddm import iaaddm
    from iasuprec import iasuprec

    g = iaaddm(f, h)
    y = iasuprec(g, f, Bc)
    return y
예제 #12
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
예제 #13
0
def iahmax(f, h=1, Bc=iasecross()):
    from iasubm import iasubm
    from iainfrec import iainfrec

    g = iasubm(f, h)
    y = iainfrec(g, f, Bc)
    return y
예제 #14
0
파일: iahmin.py 프로젝트: DiJei/ia870
def iahmin(f, h=1, Bc=iasecross()):
    from iaaddm import iaaddm
    from iasuprec import iasuprec

    g = iaaddm(f,h)
    y = iasuprec(g,f,Bc);
    return y
예제 #15
0
def iaareaopen(f, a, Bc=iasecross()):
    a = -a
    s = f.shape
    g = np.zeros_like(f).ravel()
    f1 = np.concatenate((f.ravel(), np.array([0])))
    area = -np.ones((f1.size,), np.int32)
    N = MT.iaNlut(s, MT.iase2off(Bc))
    pontos = f1.nonzero()[0]
    pontos = pontos[np.lexsort((np.arange(0, -len(pontos), -1), f1[pontos]))[::-1]]
    for p in pontos:
        for v in N[p]:
            if f1[p] < f1[v] or (f1[p] == f1[v] and v < p):
                rv = find_area(area, v)
                if rv != p:
                    if area[rv] > a or f1[p] == f1[rv]:
                        area[p] = area[p] + area[rv]
                        area[rv] = p
                    else:
                        area[p] = a
    for p in pontos[::-1]:
        if area[p] >= 0:
            g[p] = g[area[p]]
        else:
            if area[p] <= a:
                g[p] = f1[p]
    return g.reshape(s)
예제 #16
0
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
예제 #17
0
def iaedgeoff(f, Bc=iasecross()):
    from iaframe import iaframe
    from iasubm import iasubm
    from iainfrec import iainfrec

    edge = iaframe(f)
    return iasubm(f, iainfrec(edge, f, Bc))
예제 #18
0
def iaclohole(f, Bc=iasecross()):
    from iaframe import iaframe
    from ianeg import ianeg
    from iainfrec import iainfrec

    delta_f = iaframe(f)
    return ianeg(iainfrec(delta_f, ianeg(f), Bc))
예제 #19
0
파일: iahmax.py 프로젝트: DiJei/ia870
def iahmax(f, h=1, Bc=iasecross()):
    from iasubm import iasubm
    from iainfrec import iainfrec

    g = iasubm(f,h)
    y = iainfrec(g,f,Bc);
    return y
예제 #20
0
def iaasf(f, SEQ="OC", b=None, n=1):
    from iasesum import iasesum
    from iaopen import iaopen
    from iaclose import iaclose
    from iasecross import iasecross
    if b is None:
        b = iasecross(None)

    SEQ=upper(SEQ)
    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
예제 #21
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
예제 #22
0
def iaareaopen(f,a,Bc=iasecross()):
    a = -a
    s = f.shape
    g = np.zeros_like(f).ravel()
    f1 = np.concatenate((f.ravel(),np.array([0])))
    area = -np.ones((f1.size,), np.int32)
    N = MT.iaNlut(s, MT.iase2off(Bc))
    pontos = f1.nonzero()[0]
    pontos = pontos[np.lexsort((np.arange(0,-len(pontos),-1),f1[pontos]))[::-1]]
    for p in pontos:
        for v in N[p]:
            if f1[p] < f1[v] or (f1[p] == f1[v] and v < p):
                rv = find_area(area, v)
                if rv != p:
                    if area[rv] > a or f1[p] == f1[rv]:
                        area[p] = area[p] + area[rv]
                        area[rv] = p
                    else:
                        area[p] = a
    for p in pontos[::-1]:
        if area[p] >= 0:
            g[p] = g[area[p]]
        else:
            if area[p] <= a:
                g[p] = f1[p]
    return g.reshape(s)
예제 #23
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
예제 #24
0
파일: iaedgeoff.py 프로젝트: DiJei/ia870
def iaedgeoff(f, Bc=iasecross()):
    from iaframe import iaframe
    from iasubm import iasubm
    from iainfrec import iainfrec

    edge = iaframe(f)
    return iasubm( f, iainfrec(edge, f, Bc))
예제 #25
0
파일: iaclohole.py 프로젝트: DiJei/ia870
def iaclohole(f, Bc=iasecross()):
    from iaframe import iaframe
    from ianeg import ianeg
    from iainfrec import iainfrec

    delta_f = iaframe(f)
    return ianeg( iainfrec( delta_f, ianeg(f), Bc))
예제 #26
0
def iacloseth(f, b=None):
    from iasubm import iasubm
    from iaclose import iaclose
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iasubm(iaclose(f, b), f)
    return y
예제 #27
0
def iaero(f, b=None):
    from ianeg import ianeg
    from iadil import iadil
    from iasereflect import iasereflect
    from iasecross import iasecross

    if b is None: b = iasecross()
    y = ianeg(iadil(ianeg(f), iasereflect(b)))
    return y
예제 #28
0
def iaregmax(f, Bc=iasecross()):
    from iasubm import iasubm
    from iahmax import iahmax
    from iabinary import iabinary
    from iaregmin import iaregmin
    from ianeg import ianeg

    y = iasubm(f, iahmax(f, 1, Bc))
    return iabinary(y)
예제 #29
0
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
예제 #30
0
파일: iacloseth.py 프로젝트: DiJei/ia870
def iacloseth(f, b=None):
    from iasubm import iasubm
    from iaclose import iaclose
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iasubm( iaclose(f,b), f)
    return y
예제 #31
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
예제 #32
0
파일: iaregmax.py 프로젝트: DiJei/ia870
def iaregmax(f, Bc=iasecross()):
    from iasubm import iasubm
    from iahmax import iahmax
    from iabinary import iabinary
    from iaregmin import iaregmin
    from ianeg import ianeg

    y = iasubm(f, iahmax(f,1,Bc))
    return iabinary(y)
예제 #33
0
파일: iaunpad.py 프로젝트: DiJei/ia870
def iaunpad(f, B=iasecross()):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i,v=iamat2set( iaseshow(B));
    mni=minimum.reduce(i)
    mxi=maximum.reduce(i)
    g = f[-mni[0]:f.shape[0]-mxi[0], -mni[1]:f.shape[1]-mxi[1]]

    return g
예제 #34
0
def iaclose(f, b=None):
    from iaero import iaero
    from iadil import iadil
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iaero(iadil(f, b), b)

    return y
예제 #35
0
파일: iaopenth.py 프로젝트: DiJei/ia870
def iaopenth(f, b=None):
    from iasubm import iasubm
    from iaopen import iaopen
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iasubm(f, iaopen(f,b))

    return y
예제 #36
0
def iasuprec(f, g, Bc=None):
    from iacero import iacero
    from iasecross import iasecross
    if Bc is None:
        Bc = iasecross(None)

    n = product(f.shape)
    y = iacero(f, g, Bc, n)

    return y
예제 #37
0
파일: iaero.py 프로젝트: ramosapf/ia870
def iaero(f, b=None):
    from ianeg import ianeg
    from iadil import iadil
    from iasereflect import iasereflect
    from iasecross import iasecross

    if b is None:
        b = iasecross()
    y = ianeg(iadil(ianeg(f), iasereflect(b)))
    return y
예제 #38
0
파일: iaopen.py 프로젝트: DiJei/ia870
def iaopen(f, b=None):
    from iadil import iadil
    from iaero import iaero
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iadil( iaero(f,b),b)

    return y
예제 #39
0
def iaopenth(f, b=None):
    from iasubm import iasubm
    from iaopen import iaopen
    from iasecross import iasecross
    if b is None:
        b = iasecross()

    y = iasubm(f, iaopen(f, b))

    return y
예제 #40
0
def iaunpad(f, B=iasecross()):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i, v = iamat2set(iaseshow(B))
    mni = minimum.reduce(i)
    mxi = maximum.reduce(i)
    g = f[-mni[0]:f.shape[0] - mxi[0], -mni[1]:f.shape[1] - mxi[1]]

    return g
예제 #41
0
파일: iasuprec.py 프로젝트: DiJei/ia870
def iasuprec(f, g, Bc=None):
    from iacero import iacero
    from iasecross import iasecross
    if Bc is None:
        Bc = iasecross(None)


    n = product(f.shape)
    y = iacero(f,g,Bc,n);

    return y
예제 #42
0
def iacero(f, g, b=iasecross(), n=1):
    from iaunion import iaunion
    from iaero import iaero
    from 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
예제 #43
0
파일: iacdil.py 프로젝트: DiJei/ia870
def iacdil(f, g, b=iasecross(), n=1):
    from iaintersec import iaintersec
    from iadil import iadil
    from iaisequal import iaisequal

    y = iaintersec(f,g)
    for i in xrange(n):
        aux = y
        y = iaintersec( iadil(y,b),g)
        if iaisequal(y,aux): break
    return y
예제 #44
0
파일: iacero.py 프로젝트: DiJei/ia870
def iacero(f, g, b=iasecross(), n=1):
    from iaunion import iaunion
    from iaero import iaero
    from 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
예제 #45
0
def iaasfrec(f, SEQ="OC", b=iasecross(), bc=iasecross(), n=1):
    from iasesum import iasesum
    from iacloserec import iacloserec
    from iaopenrec import iaopenrec

    SEQ = upper(SEQ)
    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
예제 #46
0
파일: iaasfrec.py 프로젝트: ramosapf/ia870
def iaasfrec(f, SEQ="OC", b=iasecross(), bc=iasecross(), n=1):
    from iasesum import iasesum
    from iacloserec import iacloserec
    from iaopenrec import iaopenrec

    SEQ = upper(SEQ)
    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
예제 #47
0
def iapad(f, B=iasecross(), value=0):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i, v = iamat2set(iaseshow(B))
    mni = i.min(axis=0)
    mxi = i.max(axis=0)
    f = asarray(f)
    if size(f.shape) == 1: f = f[newaxis, :]
    g = (value * ones(array(f.shape) + mxi - mni)).astype(f.dtype)
    g[-mni[0]:g.shape[0] - mxi[0], -mni[1]:g.shape[1] - mxi[1]] = f

    return g
예제 #48
0
파일: iapad.py 프로젝트: DiJei/ia870
def iapad(f, B=iasecross(), value=0):
    from iamat2set import iamat2set
    from iaseshow import iaseshow

    i,v=iamat2set( iaseshow(B));
    mni=i.min(axis=0)
    mxi=i.max(axis=0)
    f = asarray(f)
    if size(f.shape) == 1: f = f[newaxis,:]
    g = (value * ones(array(f.shape)+mxi-mni)).astype(f.dtype)
    g[-mni[0]:g.shape[0]-mxi[0], -mni[1]:g.shape[1]-mxi[1]] = f

    return g
예제 #49
0
def iaregmin(f, Bc=iasecross(), option="binary"):
    from iahmin import iahmin
    from iaaddm import iaaddm
    from iasubm import iasubm
    from iabinary import iabinary
    from iasuprec import iasuprec
    from iaunion import iaunion
    from iathreshad import iathreshad

    if option != "binary":
        raise Exception("iaregmin accepts only binary option")

    return iabinary(iasubm(iahmin(f,1,Bc), f))
예제 #50
0
def iaskelmrec(f, B=None):
    from iabinary import iabinary
    from iaintersec import iaintersec
    from iadil import iadil
    from iaunion import iaunion
    from iasecross import iasecross
    if B is None:
        B = iasecross(None)

    y = iabinary(iaintersec(f, 0))
    for r in range(max(ravel(f)), 1, -1):
        y = iadil(iaunion(y, iabinary(f, r)), B)
    y = iaunion(y, iabinary(f, 1))
    return y
예제 #51
0
파일: iaskelmrec.py 프로젝트: DiJei/ia870
def iaskelmrec(f, B=None):
    from iabinary import iabinary
    from iaintersec import iaintersec
    from iadil import iadil
    from iaunion import iaunion
    from iasecross import iasecross
    if B is None:
        B = iasecross(None)

    y = iabinary( iaintersec(f, 0))
    for r in range(max(ravel(f)),1,-1):
        y = iadil( iaunion(y,iabinary(f,r)), B)
    y = iaunion(y, iabinary(f,1))
    return y
예제 #52
0
파일: ialabel.py 프로젝트: DiJei/ia870
def ialabel_rec(f, Bc=iasecross()):
    assert MT.iaisbinary(f),'Can only label binary image'
    faux=f.copy()
    label = 1
    y = MT.iagray( f,'uint16',0)          # zero image (output)
    x = faux.ravel().nonzero()            # get list of unlabeled pixel
    while len(x[0]):
        fmark = np.zeros_like(f)
        fmark.flat[x[0][0]] = 1           # get the first unlabeled pixel
        r = MT.iainfrec( fmark, faux, Bc) # detects all pixels connected to it
        faux -= r                         # remove them from faux
        r = MT.iagray( r,'uint16',label)  # label them with the value label
        y = MT.iaunion( y, r)             # merge them with the labeled image
        label = label + 1
        x = faux.ravel().nonzero()        # get list of unlabeled pixel
    return y
예제 #53
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
예제 #54
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
예제 #55
0
def ialabel_rec(f, Bc=iasecross()):
    assert MT.iaisbinary(f), 'Can only label binary image'
    faux = f.copy()
    label = 1
    y = MT.iagray(f, 'uint16', 0)  # zero image (output)
    x = faux.ravel().nonzero()  # get list of unlabeled pixel
    while len(x[0]):
        fmark = np.zeros_like(f)
        fmark.flat[x[0][0]] = 1  # get the first unlabeled pixel
        r = MT.iainfrec(fmark, faux, Bc)  # detects all pixels connected to it
        faux -= r  # remove them from faux
        r = MT.iagray(r, 'uint16', label)  # label them with the value label
        y = MT.iaunion(y, r)  # merge them with the labeled image
        label = label + 1
        x = faux.ravel().nonzero()  # get list of unlabeled pixel
    return y
예제 #56
0
def iaareaopen_eq(f, a, Bc=iasecross()):

    if f.dtype == np.bool:
      fr = MT.ialabel(f,Bc)      # binary area open, use area measurement
      g = MT.iablob(fr,'area')
      y = g >= a
    else:
      y = np.zeros_like(f)
      k1 = f.min()
      k2 = f.max()
      for k in xrange(k1,k2+1):   # gray-scale, use thresholding decomposition
        fk = (f >= k)
        fo = MT.iaareaopen(fk,a,Bc)
        if not fo.any():
          break
        y = MT.iaunion(y, MT.iagray(fo,f.dtype,k))
    return y