Esempio n. 1
0
def process(sortedRegions):
  # Order component list by decreasing area size
  #largest = list(Enumerable.OrderByDescending(sortedRegions, lambda x:x.Area))
  # Order component list by centroid position
  #hSortRegionList = list(Enumerable.OrderBy(sortedRegions, lambda x:x.Centroid.X))
  vSortRegionList = list(Enumerable.OrderByDescending(sortedRegions, lambda x:x.Centroid.Y))

  if len(vSortRegionList) >=6:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float(vSortRegionList[1].Centroid.X),float(vSortRegionList[2].Centroid.X),float(vSortRegionList[3].Centroid.X),float(vSortRegionList[4].Centroid.X),float(vSortRegionList[5].Centroid.X))
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float(vSortRegionList[1].Centroid.Y),float(vSortRegionList[2].Centroid.Y),float(vSortRegionList[3].Centroid.Y),float(vSortRegionList[4].Centroid.Y),float(vSortRegionList[5].Centroid.Y))
  if len(vSortRegionList) ==5:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float(vSortRegionList[1].Centroid.X),float(vSortRegionList[2].Centroid.X),float(vSortRegionList[3].Centroid.X),float(vSortRegionList[4].Centroid.X),float.NaN)
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float(vSortRegionList[1].Centroid.Y),float(vSortRegionList[2].Centroid.Y),float(vSortRegionList[3].Centroid.Y),float(vSortRegionList[4].Centroid.Y),float.NaN)
  if len(vSortRegionList) ==4:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float(vSortRegionList[1].Centroid.X),float(vSortRegionList[2].Centroid.X),float(vSortRegionList[3].Centroid.X),float.NaN,float.NaN)
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float(vSortRegionList[1].Centroid.Y),float(vSortRegionList[2].Centroid.Y),float(vSortRegionList[3].Centroid.Y),float.NaN,float.NaN)
  if len(vSortRegionList) ==3:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float(vSortRegionList[1].Centroid.X),float(vSortRegionList[2].Centroid.X),float.NaN,float.NaN,float.NaN)
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float(vSortRegionList[1].Centroid.Y),float(vSortRegionList[2].Centroid.Y),float.NaN,float.NaN,float.NaN)
  elif len(vSortRegionList) ==2:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float(vSortRegionList[1].Centroid.X),float.NaN,float.NaN,float.NaN,float.NaN)
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float(vSortRegionList[1].Centroid.Y),float.NaN,float.NaN,float.NaN,float.NaN)
  elif len(vSortRegionList) == 1:
    xCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.X),float.NaN,float.NaN,float.NaN,float.NaN,float.NaN) 
    yCentroidList=Tuple.Create(float(vSortRegionList[0].Centroid.Y),float.NaN,float.NaN,float.NaN,float.NaN,float.NaN)
  else:
    xCentroidList=Tuple.Create(float.NaN,float.NaN,float.NaN,float.NaN,float.NaN,float.NaN)
    yCentroidList=Tuple.Create(float.NaN,float.NaN,float.NaN,float.NaN,float.NaN,float.NaN)

  return Tuple.Create(xCentroidList, yCentroidList)
def process(sortedRegions):
    vSortRegionList = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))
    if len(vSortRegionList) >= 3:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[2].Contour.ToArray[Point]())))
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y),
            Point2f(vSortRegionList[2].Centroid.X,
                    vSortRegionList[2].Centroid.Y))
        tipList = Tuple.Create(
            Point2f(FindTipPoint(vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindTipPoint(vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindTipPoint(vSortRegionList[2].Contour.ToArray[Point]())))
    elif len(vSortRegionList) == 2:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())), NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y), NaNPoint)
        tipList = Tuple.Create(
            Point2f(FindTipPoint(vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindTipPoint(vSortRegionList[1].Contour.ToArray[Point]())),
            NaNPoint)
    elif len(vSortRegionList) == 1:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())), NaNPoint,
            NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y), NaNPoint, NaNPoint)
        tipList = Tuple.Create(
            Point2f(FindTipPoint(vSortRegionList[0].Contour.ToArray[Point]())),
            NaNPoint, NaNPoint)
    else:
        baseList = Tuple.Create(NaNPoint, NaNPoint, NaNPoint)
        centroidList = Tuple.Create(NaNPoint, NaNPoint, NaNPoint)
        tipList = Tuple.Create(NaNPoint, NaNPoint, NaNPoint)

    return Tuple.Create(baseList, centroidList, tipList)
def process(sortedRegions):
    global base, centroidLoc, centroidVel

    vSortRegionList = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))

    if len(vSortRegionList) >= 3:
        blob1Index = 2
        newbase = Point2f(
            FindTipPoint(vSortRegionList[blob1Index].Contour.ToArray[Point]()))
        return newbase  #vSortRegionList[blob1Index].Orientation
    else:
        return NaNPoint  #float(0)
def process(value):
    global base
    # Order blob list by descending area
    #largest = list(Enumerable.OrderByDescending(value, lambda x:x.Area))
    # Order component list by rightmost centroid
    rightmost = list(
        Enumerable.OrderByDescending(value, lambda x: x.Centroid.X))

    if len(rightmost) >= 1:
        blob1Index = 0
        currbase = base
        newbase = max(rightmost[blob1Index].Contour.ToArray[Point]())
        if base is None:
            base = newbase
            #return float.NaN
        elif abs(distfromlastframe(currbase, newbase)) < 20:
            base = newbase
            #float(largest[0].Orientation)
            #return distfromlastframe(currbase, base)
        else:  # find which blob is which instead
            if len(rightmost) >= blob1Index + 2:
                nextbase = max(rightmost[blob1Index +
                                         1].Contour.ToArray[Point]())
                if abs(distfromlastframe(currbase, nextbase)) < 20:
                    blob1Index = blob1Index + 1
                    base = nextbase
                else:
                    if len(rightmost) >= blob1Index + 3:
                        nextbase = max(rightmost[blob1Index +
                                                 2].Contour.ToArray[Point]())
                        if abs(distfromlastframe(currbase, nextbase)) < 20:
                            blob1Index = blob1Index + 2
                            base = nextbase
                        else:  #keep previous value
                            blob1Index = float.NaN
                            base = base
                    else:
                        blob1Index = float.NaN
            else:
                blob1Index = float.NaN
            #return distfromlastframe(currbase, base)
        blob1Index = float(blob1Index)
    else:
        # otherwise, return nan
        base = None
        blob1Index = float.NaN

    return Tuple.Create(blob1Index, len(rightmost))
Esempio n. 5
0
def process(sortedRegions):
    global noWhisker, whiskerIndex, currBase
    # Order whisker components list by base point, bottom to top
    vSortWhiskers = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))

    if noWhisker is True:  #on first pass, mostly
        whiskerIndex = 0
        currBase = FindBasePoint(
            vSortWhiskers[whiskerIndex].Contour.ToArray[Point]())
        #print("init")

    # Compare base points and find closest base, within spatial treshold limits (typically, either index 0 or 1)
    # ToDo: need to find what to do when tracked whisker has jumped to a neigboring one.
    # Try and prevent these limit cases by comparing centroids. Or take direction / velocity into account
    if len(vSortWhiskers) >= 1:
        baseDist = distThd
        bestIdx = whiskerIndex
        for wIdx, wCComp in enumerate(vSortWhiskers):
            thatBase = FindBasePoint(wCComp.Contour.ToArray[Point]())
            if DistBetweenPoints(currBase, thatBase) < baseDist:
                baseDist = DistBetweenPoints(currBase, thatBase)
                bestIdx = wIdx
        if baseDist < distThd:
            whiskerIndex = bestIdx
            currBase = FindBasePoint(
                vSortWhiskers[whiskerIndex].Contour.ToArray[Point]())
        else:
            whiskerIndex = float.NaN
        noWhisker = False
    else:
        # if no whisker components, return nan
        noWhisker = True
        whiskerIndex = float.NaN

    Component = ConnectedComponentCollection(sortedRegions.ImageSize)
    if Single.IsNaN(whiskerIndex) == False:
        Component.Add(vSortWhiskers[int(whiskerIndex)])

    return Component
def FindTipPoint(inputPointArray):
    pointList = Enumerable.OrderByDescending(inputPointArray, lambda x: x.X)
    lastPoint = Enumerable.First(pointList)
    return lastPoint
Esempio n. 7
0
def process(sortedRegions):
    # Order component list by decreasing area size
    #largest = list(Enumerable.OrderByDescending(sortedRegions, lambda x:x.Area))
    # Order component list by centroid position
    #hSortRegionList = list(Enumerable.OrderBy(sortedRegions, lambda x:x.Centroid.X))
    vSortRegionList = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))
    if len(vSortRegionList) >= 6:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[2].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[3].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[4].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[5].Contour.ToArray[Point]())))
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y),
            Point2f(vSortRegionList[2].Centroid.X,
                    vSortRegionList[2].Centroid.Y),
            Point2f(vSortRegionList[3].Centroid.X,
                    vSortRegionList[3].Centroid.Y),
            Point2f(vSortRegionList[4].Centroid.X,
                    vSortRegionList[4].Centroid.Y),
            Point2f(vSortRegionList[5].Centroid.X,
                    vSortRegionList[5].Centroid.Y))
    elif len(vSortRegionList) == 5:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[2].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[3].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[4].Contour.ToArray[Point]())), NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y),
            Point2f(vSortRegionList[2].Centroid.X,
                    vSortRegionList[2].Centroid.Y),
            Point2f(vSortRegionList[3].Centroid.X,
                    vSortRegionList[3].Centroid.Y),
            Point2f(vSortRegionList[4].Centroid.X,
                    vSortRegionList[4].Centroid.Y), NaNPoint)
    elif len(vSortRegionList) == 4:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[2].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[3].Contour.ToArray[Point]())), NaNPoint,
            NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y),
            Point2f(vSortRegionList[2].Centroid.X,
                    vSortRegionList[2].Centroid.Y),
            Point2f(vSortRegionList[3].Centroid.X,
                    vSortRegionList[3].Centroid.Y), NaNPoint, NaNPoint)
    elif len(vSortRegionList) == 3:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[2].Contour.ToArray[Point]())), NaNPoint,
            NaNPoint, NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y),
            Point2f(vSortRegionList[2].Centroid.X,
                    vSortRegionList[2].Centroid.Y), NaNPoint, NaNPoint,
            NaNPoint)
    elif len(vSortRegionList) == 2:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())),
            Point2f(FindBasePoint(
                vSortRegionList[1].Contour.ToArray[Point]())), NaNPoint,
            NaNPoint, NaNPoint, NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y),
            Point2f(vSortRegionList[1].Centroid.X,
                    vSortRegionList[1].Centroid.Y), NaNPoint, NaNPoint,
            NaNPoint, NaNPoint)
    elif len(vSortRegionList) == 1:
        baseList = Tuple.Create(
            Point2f(FindBasePoint(
                vSortRegionList[0].Contour.ToArray[Point]())), NaNPoint,
            NaNPoint, NaNPoint, NaNPoint, NaNPoint)
        centroidList = Tuple.Create(
            Point2f(vSortRegionList[0].Centroid.X,
                    vSortRegionList[0].Centroid.Y), NaNPoint, NaNPoint,
            NaNPoint, NaNPoint, NaNPoint)
    else:
        baseList = Tuple.Create(NaNPoint, NaNPoint, NaNPoint, NaNPoint,
                                NaNPoint, NaNPoint)
        centroidList = Tuple.Create(NaNPoint, NaNPoint, NaNPoint, NaNPoint,
                                    NaNPoint, NaNPoint)

    return Tuple.Create(baseList, centroidList)
Esempio n. 8
0
def process(sortedRegions):
    global base, centroidLoc, centroidVel
    # Order blob list by descending Y base point (ie, bottom to top)
    vSortRegionList = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))

    if len(vSortRegionList) >= 1:
        blob1Index = 0
        currbase = base
        newbase = FindBasePoint(
            vSortRegionList[blob1Index].Contour.ToArray[Point]
            ())  #vSortRegionList[blob1Index].Contour.ToArray[Point]()[0]
        if base is None:
            base = newbase
            #return float.NaN
        elif abs(VDistFromLastFrame(currbase, newbase)) < distThd:
            base = newbase
            #float(largest[0].Orientation)
            #return distfromlastframe(currbase, base)
        else:  # find which blob is which instead
            if len(vSortRegionList) >= blob1Index + 2:
                nextbase = FindBasePoint(
                    vSortRegionList[blob1Index + 1].Contour.ToArray[Point]())
                if abs(VDistFromLastFrame(currbase, nextbase)) < distThd:
                    blob1Index = blob1Index + 1
                    base = nextbase
                else:
                    if len(vSortRegionList) >= blob1Index + 3:
                        nextbase = FindBasePoint(
                            vSortRegionList[blob1Index +
                                            2].Contour.ToArray[Point]())
                        if abs(VDistFromLastFrame(currbase,
                                                  nextbase)) < distThd:
                            blob1Index = blob1Index + 2
                            base = nextbase
                        else:  #keep previous value
                            blob1Index = float.NaN
                            base = base
                    else:
                        blob1Index = float.NaN
            else:
                blob1Index = float.NaN
            #return distfromlastframe(currbase, base)
        blob1Index = float(blob1Index)
    else:
        # otherwise, return nan
        base = None
        blob1Index = float.NaN

    #return Tuple.Create(blob1Index,len(leftmost))

    Component = ConnectedComponentCollection(sortedRegions.ImageSize)
    vSortRegionList = list(
        Enumerable.OrderByDescending(
            sortedRegions, lambda x: FindBasePoint(x.Contour.ToArray[Point]
                                                   ()).Y))
    if Single.IsNaN(blob1Index) == False:
        Component.Add(vSortRegionList[int(blob1Index)])
        if int(blob1Index) + 1 <= len(vSortRegionList) - 1:
            Component.Add(vSortRegionList[int(blob1Index) + 1])
        if int(blob1Index) + 2 <= len(vSortRegionList) - 1:
            Component.Add(vSortRegionList[int(blob1Index) + 2])

    return Component