コード例 #1
0
def iadist(f, Bc=iasecross(), METRIC=None):
    from ia870 import iagray, iaintersec, iaisequal, iaero, iasebox

    if METRIC is not None: METRIC = METRIC.upper()
    f = iagray(f, 'uint16')
    y = iaintersec(f, 0)
    if (METRIC == 'EUCLIDEAN') or (METRIC == 'EUC2'):
        f = np.int32(f)
        b = np.int32(np.zeros((3, 3)))
        i = 1
        while np.any(f != y):
            a4, a2 = -4 * i + 2, -2 * i + 1
            b = np.int32([[a4, a2, a4], [a2, 0, a2], [a4, a2, a4]])
            y = f
            i = i + 1
            f = iaero(f, b)
        if METRIC == 'EUCLIDEAN':
            y = np.uint16(np.sqrt(f) + 0.5)
    else:
        if iaisequal(Bc, iasecross()):
            b = np.int32([[-2147483647, -1, -2147483647], [-1, 0, -1],
                          [-2147483647, -1, -2147483647]])
        elif iaisequal(Bc, iasebox()):
            b = np.int32([[-1, -1, -1], [-1, 0, -1], [-1, -1, -1]])
        else:
            b = Bc
        while np.any(f != y):
            y = f
            f = iaero(f, b)
    return y
コード例 #2
0
def iagradm(f, Bdil=None, Bero=None):
    from ia870 import iasubm,iadil,iaero,iasecross

    if Bdil is None: Bdil = iasecross()
    if Bero is None: Bero = iasecross()

    y = iasubm( iadil(f,Bdil),iaero(f,Bero))
    return y
コード例 #3
0
ファイル: iawatershed.py プロジェクト: mariecpereira/IA369Z
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
コード例 #4
0
def iaclose(f, b=None):
    from ia870 import iaero, iadil, iasecross

    if b is None:
        b = iasecross()

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

    return y
コード例 #5
0
ファイル: iawatershed.py プロジェクト: DiJei/ia870
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
コード例 #6
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
コード例 #7
0
ファイル: iacwatershed.py プロジェクト: DiJei/ia870
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
コード例 #8
0
ファイル: get_spline.py プロジェクト: mariecpereira/IA369Z
def get_spline(seg, s):
    nz = np.nonzero(seg)
    x1, x2, y1, y2 = np.amin(nz[0]), np.amax(nz[0]), np.amin(nz[1]), np.amax(
        nz[1])
    M0 = seg[x1 - 5:x2 + 5, y1 - 5:y2 + 5]
    nescala = [4 * M0.shape[-2], 4 * M0.shape[-1]]
    M0 = FW.resizedti(M0, nescala).astype('bool')
    con_M0 = np.logical_xor(MM.iaero(M0), M0)
    seq = FW.get_seq_graph(con_M0)
    tck, _ = spline.splprep(seq, k=5, s=s)
    return tck
コード例 #9
0
ファイル: iablob.py プロジェクト: DiJei/ia870
def iablob(fr, measurement, option="image"):

    measurement = upper(measurement)
    option      = upper(option)
    if len(fr.shape) == 1: fr = fr[newaxis,:]
    n = fr.max()
    if   option      == 'DATA':        y = []
    elif measurement == 'CENTROID':    y = np.zeros(fr.shape,bool)
    elif measurement == 'BOUNDINGBOX': y = np.zeros(fr.shape,bool)
    elif measurement == 'PERIMETER':   y = np.zeros(fr.shape,np.int32)
    elif measurement == 'AREA':        y = np.zeros(fr.shape,np.int32)
    else:                              y = np.zeros(fr.shape)

    if measurement == 'AREA':
        area = np.bincount(fr.ravel())
        if option == 'DATA':
            y = area[1::]
        else:
            for i in xrange(1,n+1):
               y[fr==i] = area[i]

    elif measurement == 'CENTROID':
        for i in xrange(1,n+1):
            aux  = (fr==i)
            xind,yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum()/area,yind.sum()/area]
            if option == 'DATA': y.append([centroid[1],centroid[0]])
            else               : y[centroid[0],centroid[1]] = 1

    elif measurement == 'BOUNDINGBOX':
        for i in xrange(1,n+1):
            aux = (fr==i)
            col, = np.nonzero(aux.any(0))
            row, = np.nonzero(aux.any(1))
            if option == 'DATA': y.append([col[0],row[0],col[-1],row[-1]])
            else:
                y[row[0]:row[-1],col[0] ] = 1
                y[row[0]:row[-1],col[-1]] = 1
                y[row[0], col[0]:col[-1]] = 1
                y[row[-1],col[0]:col[-1]] = 1

    elif measurement == 'PERIMETER':
        Bc = ia870.iasecross()
        for i in xrange(1,n+1):
           aux = fr == i
           grad = aux - ia870.iaero(aux,Bc)
           if option == 'DATA': y.append(grad.sum())
           else:
               y[aux] = grad.sum()

    elif measurement == 'CIRCULARITY':
        Bc = ia870.iasecross()
        area = np.bincount(fr.ravel())
        perim = []
        for i in xrange(1,n+1):
           aux = fr == i
           grad = aux - ia870.iaero(aux,Bc)
           perim.append(grad.sum())
           if option != 'DATA':
               y[aux] = 4*np.pi*area[i]/(perim[i-1]**2)
        if option == 'DATA':
            perim = np.array(perim)
            y = 4*np.pi*area[1::]/(perim**2)

    elif measurement == 'ASPECTRATIO':
        for i in xrange(1,n+1):
            aux = (fr==i)
            col, = np.nonzero(aux.any(0))
            row, = np.nonzero(aux.any(1))
            if option == 'DATA': y.append(1.*(min(col[-1]-col[0],row[-1]-row[0])+1)/(max(col[-1]-col[0],row[-1]-row[0])+1))
            else:
                y[aux] = 1.*(min(col[-1]-col[0],row[-1]-row[0])+1)/(max(col[-1]-col[0],row[-1]-row[0])+1)

    elif measurement == 'COMPACTNESS':
        for i in xrange(1,n+1):
            aux  = (fr==i)
            xind,yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum()/area,yind.sum()/area]
            m20 = ((1.*xind-centroid[0])**2).sum()/area
            m02 = ((1.*yind-centroid[1])**2).sum()/area
            compactness = area/(2*np.pi*(m20+m02))
            if option == 'DATA': y.append(compactness)
            else               : y[aux] = compactness

    elif measurement == 'ECCENTRICITY':
        for i in xrange(1,n+1):
            aux  = (fr==i)
            xind,yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum()/area,yind.sum()/area]
            m11 = ((1.*xind-centroid[0])*(yind-centroid[1])).sum()/area
            m20 = ((1.*xind-centroid[0])**2).sum()/area
            m02 = ((1.*yind-centroid[1])**2).sum()/area
            eccentricity = sqrt((m20-m02)**2+4*m11**2)/(m20+m02)
            if option == 'DATA': y.append(eccentricity)
            else               : y[aux] = eccentricity

    else:
        print "Measurement option should be 'AREA','CENTROID', 'BOUNDINGBOX', 'PERIMETER', "
        print "'ASPECTRATIO', 'CIRCULARITY', 'COMPACTNESS' or 'ECCENTRICITY'."

    return np.array(y)
コード例 #10
0
ファイル: iablob.py プロジェクト: mariecpereira/IA369Z
def iablob(fr, measurement, option="image"):

    measurement = upper(measurement)
    option = upper(option)
    if len(fr.shape) == 1: fr = fr[newaxis, :]
    n = fr.max()
    if option == 'DATA': y = []
    elif measurement == 'CENTROID': y = np.zeros(fr.shape, bool)
    elif measurement == 'BOUNDINGBOX': y = np.zeros(fr.shape, bool)
    elif measurement == 'PERIMETER': y = np.zeros(fr.shape, np.int32)
    elif measurement == 'AREA': y = np.zeros(fr.shape, np.int32)
    else: y = np.zeros(fr.shape)

    if measurement == 'AREA':
        area = np.bincount(fr.ravel())
        if option == 'DATA':
            y = area[1::]
        else:
            for i in xrange(1, n + 1):
                y[fr == i] = area[i]

    elif measurement == 'CENTROID':
        for i in xrange(1, n + 1):
            aux = (fr == i)
            xind, yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum() / area, yind.sum() / area]
            if option == 'DATA': y.append([centroid[1], centroid[0]])
            else: y[centroid[0], centroid[1]] = 1

    elif measurement == 'BOUNDINGBOX':
        for i in xrange(1, n + 1):
            aux = (fr == i)
            col, = np.nonzero(aux.any(0))
            row, = np.nonzero(aux.any(1))
            if option == 'DATA': y.append([col[0], row[0], col[-1], row[-1]])
            else:
                y[row[0]:row[-1], col[0]] = 1
                y[row[0]:row[-1], col[-1]] = 1
                y[row[0], col[0]:col[-1]] = 1
                y[row[-1], col[0]:col[-1]] = 1

    elif measurement == 'PERIMETER':
        Bc = ia870.iasecross()
        for i in xrange(1, n + 1):
            aux = fr == i
            grad = aux - ia870.iaero(aux, Bc)
            if option == 'DATA': y.append(grad.sum())
            else:
                y[aux] = grad.sum()

    elif measurement == 'CIRCULARITY':
        Bc = ia870.iasecross()
        area = np.bincount(fr.ravel())
        perim = []
        for i in xrange(1, n + 1):
            aux = fr == i
            grad = aux - ia870.iaero(aux, Bc)
            perim.append(grad.sum())
            if option != 'DATA':
                y[aux] = 4 * np.pi * area[i] / (perim[i - 1]**2)
        if option == 'DATA':
            perim = np.array(perim)
            y = 4 * np.pi * area[1::] / (perim**2)

    elif measurement == 'ASPECTRATIO':
        for i in xrange(1, n + 1):
            aux = (fr == i)
            col, = np.nonzero(aux.any(0))
            row, = np.nonzero(aux.any(1))
            if option == 'DATA':
                y.append(1. * (min(col[-1] - col[0], row[-1] - row[0]) + 1) /
                         (max(col[-1] - col[0], row[-1] - row[0]) + 1))
            else:
                y[aux] = 1. * (min(col[-1] - col[0], row[-1] - row[0]) + 1) / (
                    max(col[-1] - col[0], row[-1] - row[0]) + 1)

    elif measurement == 'COMPACTNESS':
        for i in xrange(1, n + 1):
            aux = (fr == i)
            xind, yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum() / area, yind.sum() / area]
            m20 = ((1. * xind - centroid[0])**2).sum() / area
            m02 = ((1. * yind - centroid[1])**2).sum() / area
            compactness = area / (2 * np.pi * (m20 + m02))
            if option == 'DATA': y.append(compactness)
            else: y[aux] = compactness

    elif measurement == 'ECCENTRICITY':
        for i in xrange(1, n + 1):
            aux = (fr == i)
            xind, yind = np.nonzero(aux)
            area = len(xind)
            centroid = [xind.sum() / area, yind.sum() / area]
            m11 = ((1. * xind - centroid[0]) *
                   (yind - centroid[1])).sum() / area
            m20 = ((1. * xind - centroid[0])**2).sum() / area
            m02 = ((1. * yind - centroid[1])**2).sum() / area
            eccentricity = sqrt((m20 - m02)**2 + 4 * m11**2) / (m20 + m02)
            if option == 'DATA': y.append(eccentricity)
            else: y[aux] = eccentricity

    else:
        print "Measurement option should be 'AREA','CENTROID', 'BOUNDINGBOX', 'PERIMETER', "
        print "'ASPECTRATIO', 'CIRCULARITY', 'COMPACTNESS' or 'ECCENTRICITY'."

    return np.array(y)