Esempio n. 1
0
def find_ellipses2( dfore , bw, dofix=True ):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""

    # check number of above-threshold pixels
    rows, cols = num.nonzero( bw )

    # find connected components
    (L,ncc) = meas.label(bw)
    
    # make sure there aren't too many connected components
    if ncc > params.max_n_clusters:
        warn( "too many objects found (>%d); truncating object search"%(params.max_n_clusters) )
        # for now, just throw out the last connected components.
        # in the future, we can sort based on area and keep those
        # with the largest area. hopefully, this never actually
        # happens.
        ncc = params.max_n_clusters
        L[L >= ncc] = 0
        
    # fit ellipses
    ellipses = est.weightedregionprops(L,ncc,dfore)

    if dofix:

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses,L,dfore)

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses,L,dfore)

    return (ellipses,L)
Esempio n. 2
0
def find_ellipses(dfore, L, ncc, dofix=True):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""

    if DEBUG_TRACKINGSETTINGS:
        print 'ncc = ' + str(ncc) + ', max(L) = ' + str(
            num.max(L)) + ', nnz(L) = ' + str(
                num.flatnonzero(L).shape) + ', sum(dfore) = ' + str(
                    num.sum(num.sum(dfore)))

    # fit ellipses
    ellipses = est.weightedregionprops(L, ncc, dfore)

    if DEBUG_TRACKINGSETTINGS:
        print 'initial list of ellipses:'
        for i in range(len(ellipses)):
            print 'ellipse[%d] = ' % i + str(ellipses[i])

    #print 'time to fit ellipses: %.2f'%(time.time() - last_time)

    if dofix:

        # store current time to find out how long fitting ellipses takes
        last_time = time.time()

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses, L, dfore)

        #print 'after fixing small, ellipses = '
        #for i in range(len(ellipses)):
        #    print 'ellipse[%d] = '%i + str(ellipses[i])

        #print 'time to fix small ellipses: %.2f'%(time.time() - last_time)

        last_time = time.time()

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses, L, dfore)

        if DEBUG_TRACKINGSETTINGS:
            print 'after fixing large, ellipses ='
            for i in range(len(ellipses)):
                print 'ellipse[%d] = ' % i + str(ellipses[i])

        #print 'time to fix large ellipses: %.2f'%(time.time() - last_time)

        #est.deleteellipses(ellipses)

    return ellipses
Esempio n. 3
0
def find_ellipses(dfore, L, ncc, dofix=True):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""

    if DEBUG_TRACKINGSETTINGS:
        print "ncc = " + str(ncc) + ", max(L) = " + str(num.max(L)) + ", nnz(L) = " + str(
            num.flatnonzero(L).shape
        ) + ", sum(dfore) = " + str(num.sum(num.sum(dfore)))

    # fit ellipses
    ellipses = est.weightedregionprops(L, ncc, dfore)

    if DEBUG_TRACKINGSETTINGS:
        print "initial list of ellipses:"
        for i in range(len(ellipses)):
            print "ellipse[%d] = " % i + str(ellipses[i])

    # print 'time to fit ellipses: %.2f'%(time.time() - last_time)

    if dofix:

        # store current time to find out how long fitting ellipses takes
        last_time = time.time()

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses, L, dfore)

        # print 'after fixing small, ellipses = '
        # for i in range(len(ellipses)):
        #    print 'ellipse[%d] = '%i + str(ellipses[i])

        # print 'time to fix small ellipses: %.2f'%(time.time() - last_time)

        last_time = time.time()

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses, L, dfore)

        if DEBUG_TRACKINGSETTINGS:
            print "after fixing large, ellipses ="
            for i in range(len(ellipses)):
                print "ellipse[%d] = " % i + str(ellipses[i])

        # print 'time to fix large ellipses: %.2f'%(time.time() - last_time)

        # est.deleteellipses(ellipses)

    return ellipses
Esempio n. 4
0
def find_ellipses2( dfore , L, ncc, dofix=True ):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""
        
    # fit ellipses
    ellipses = est.weightedregionprops(L,ncc,dfore)

    if dofix:

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses,L,dfore)

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses,L,dfore)

    return (ellipses,L)
Esempio n. 5
0
def find_ellipses2(dfore, L, ncc, dofix=True):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""

    # fit ellipses
    ellipses = est.weightedregionprops(L, ncc, dfore)

    if dofix:

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses, L, dfore)

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses, L, dfore)

    return (ellipses, L)
Esempio n. 6
0
def find_ellipses( dfore , bw, dofix=True ):
    """Fits ellipses to connected components in image.
    Returns an EllipseList, each member representing
    the x,y position and orientation of a single fly."""

    # check number of above-threshold pixels
    rows, cols = num.nonzero( bw )

    # store current time to find out how long computing ccs takes
    last_time = time.time()

    # find connected components
    (L,ncc) = meas.label(bw)

    # make sure there aren't too many connected components
    if ncc > params.max_n_clusters:
        warn( "too many objects found (>%d); truncating object search"%(params.max_n_clusters) )
        # for now, just throw out the last connected components.
        # in the future, we can sort based on area and keep those
        # with the largest area. hopefully, this never actually
        # happens.
        ncc = params.max_n_clusters
        L[L >= ncc] = 0

    #print 'time to compute connected components: %.2f'%(time.time()-last_time)

    # store current time to find out how long fitting ellipses takes
    last_time = time.time()
        
    # fit ellipses
    ellipses = est.weightedregionprops(L,ncc,dfore)

    #print 'initial list of ellipses:'
    #for i in range(len(ellipses)):
    #    print 'ellipse[%d] = '%i + str(ellipses[i])

    #print 'time to fit ellipses: %.2f'%(time.time() - last_time)

    if dofix:

        # store current time to find out how long fitting ellipses takes
        last_time = time.time()

        # check if any are small, and [try to] fix those
        est.fixsmall(ellipses,L,dfore)

        #print 'after fixing small, ellipses = '
        #for i in range(len(ellipses)):
        #    print 'ellipse[%d] = '%i + str(ellipses[i])

        #print 'time to fix small ellipses: %.2f'%(time.time() - last_time)

        last_time = time.time()

        # check if any are large, and [try to] fix those
        est.fixlarge(ellipses,L,dfore)

        #print 'after fixing large, ellipses = \n'
        #for i in range(len(ellipses)):
        #    print 'ellipse[%d] = '%i + str(ellipses[i])

        #print 'time to fix large ellipses: %.2f'%(time.time() - last_time)

        #est.deleteellipses(ellipses)

    return ellipses
Esempio n. 7
0
def find_ellipses(dfore, L, ncc, dofix=True, return_vals=False):
    """Fits ellipses to connected components in image.
    Returns a list of ellipses, each item representing
    the x,y position and orientation of a single fly."""
    if DEBUG_TRACKINGSETTINGS:
        print 'ncc = ' + str(ncc) + ', max(L) = ' + str(
            num.max(L)) + ', nnz(L) = ' + str(
                num.flatnonzero(L).shape) + ', sum(dfore) = ' + str(
                    num.sum(num.sum(dfore)))

    # fit ellipses
    ellipses = est.weightedregionprops(L, ncc, dfore)

    if return_vals:
        ellipsescopy = [ell.copy() for ell in ellipses]

    if DEBUG_TRACKINGSETTINGS:
        print 'initial list of ellipses:'
        for i in range(len(ellipses)):
            print 'ellipse[%d] = ' % i + str(ellipses[i])

    if dofix or return_vals:
        # check if any are small, and [try to] fix those
        (ellsmall, didlowerthresh, didmerge,
         diddelete) = est.fixsmall(ellipses, L, dfore, return_vals)
        # "ellipses" are fixed in place

        # check if any are large, and [try to] fix those
        (elllarge, didsplit) = est.fixlarge(ellipses, L, dfore, return_vals)

        if DEBUG_TRACKINGSETTINGS:
            print 'after fixing large, ellipses ='
            for i in range(len(ellipses)):
                print 'ellipse[%d] = ' % i + str(ellipses[i])

        if params.enforce_minmax_shape:
            # enforce shape parameters on remaining ellipses
            for ell in ellipses:
                if ell.area() < params.minshape.area or \
                       ell.area() > params.maxshape.area or \
                       ell.size.height < params.minshape.major or \
                       ell.size.height > params.maxshape.major or \
                       ell.size.width < params.minshape.minor or \
                       ell.size.width > params.maxshape.minor or \
                       ell.eccentricity() < params.minshape.ecc or \
                       ell.eccentricity() > params.maxshape.ecc:
                    # compare ell.eccentricity() to params.minshape.ecc because
                    # the .ecc was calculated from the distribution of eccentricity(),
                    # whereas params.minshape.eccentricity() would just be the
                    # eccentricity of params.minshape alone
                    if DEBUG_TRACKINGSETTINGS and False:
                        print params.minshape.area, ell.area(
                        ), params.maxshape.area, (
                            ell.area() < params.minshape.area
                            or ell.area() > params.maxshape.area)
                        print params.minshape.major, ell.size.height, params.maxshape.major, (
                            ell.size.height < params.minshape.major
                            or ell.size.height > params.maxshape.major)
                        print params.minshape.minor, ell.size.width, params.maxshape.minor, (
                            ell.size.width < params.minshape.minor
                            or ell.size.width > params.maxshape.minor)
                        print params.minshape.ecc, ell.eccentricity(
                        ), params.maxshape.ecc, (
                            ell.eccentricity() < params.minshape.ecc
                            or ell.eccentricity() > params.maxshape.ecc)

                    ell.size.height = 0
            est.deleteellipses(ellipses, L)

            if DEBUG_TRACKINGSETTINGS:
                print "minshape:", params.minshape
                print "maxshape:", params.maxshape
                print 'after enforcing min/max shapes, ellipses ='
                for i in range(len(ellipses)):
                    print 'ellipse[%d] = ' % i + str(ellipses[i])

    if return_vals:
        return (ellipsescopy, ellsmall, elllarge, didlowerthresh, didmerge,
                diddelete, didsplit)
    else:
        return ellipses