Exemplo n.º 1
0
def getModelFromPoints(sourcePoints, targetPoints):
	rigidModel = RigidModel2D()
	pointMatches = HashSet()
	for a in zip(sourcePoints, targetPoints):
		pm = PointMatch(Point([a[0][0], a[0][1]]), Point([a[1][0], a[1][1]]))
		pointMatches.add(pm)
	rigidModel.fit(pointMatches)
	return rigidModel
Exemplo n.º 2
0
 def __init__(self, center, p1, d1, p2, d2):
     """
    center, p1, p2 are 3 RealLocalizable, with center being the center point
    and p1, p2 being the wings (the other two points).
    p1 is always closer to center than p2 (d1 < d2)
    d1, d2 are the square distances from center to p1, p2
    (which we could compute here, but RadiusNeighborSearchOnKDTree did it already).
 """
     self.position = Point(self.array(center))
     v1 = Vector3f(*self.subtract(p1, center))
     v2 = Vector3f(*self.subtract(p2, center))
     self.angle = v1.angle(v2)  # in radians
     self.len1 = d1  # same as v1.lengthSquared()
     self.len2 = d2  # same as v2.lengthSquared()
class Constellation:
  """ Expects 3 scalars and an iterable of scalars. """
  def __init__(self, angle, len1, len2, coords):
    self.angle = angle
    self.len1 = len1
    self.len2 = len2
    self.position = Point(array(coords, 'd'))

  def matches(self, other, angle_epsilon, len_epsilon_sq):
    """ Compare the angles, if less than epsilon, compare the vector lengths.
       Return True when deemed similar within measurement error brackets. """
    return abs(self.angle - other.angle) < angle_epsilon \
       and abs(self.len1 - other.len1) + abs(self.len2 - other.len2) < len_epsilon_sq

  @staticmethod
  def subtract(loc1, loc2):
    return (loc1.getFloatPosition(d) - loc2.getFloatPosition(d)
            for d in xrange(loc1.numDimensions()))

  @staticmethod
  def fromSearch(center, p1, d1, p2, d2):
    """ center, p1, p2 are 3 RealLocalizable, with center being the peak
        and p1, p2 being the wings (the other two points).
        p1 is always closer to center than p2 (d1 < d2).
        d1, d2 are the square distances from center to p1, p2
        (could be computed here, but RadiusNeighborSearchOnKDTree did it). """
    pos = tuple(center.getFloatPosition(d) for d in xrange(center.numDimensions()))
    v1 = Vector3f(Constellation.subtract(p1, center))
    v2 = Vector3f(Constellation.subtract(p2, center))
    return Constellation(v1.angle(v2), d1, d2, pos)

  @staticmethod
  def fromRow(row):
    """ Expects: row = [angle, len1, len2, x, y, z] """
    return Constellation(row[0], row[1], row[2], row[3:])

  def asRow(self):
    "Returns: [angle, len1, len2, position.x, position,y, position.z"
    return (self.angle, self.len1, self.len2) + tuple(self.position.getW())

  @staticmethod
  def csvHeader():
    return ["angle", "len1", "len2", "x", "y", "z"]
 def __init__(self, angle, len1, len2, coords):
   self.angle = angle
   self.len1 = len1
   self.len2 = len2
   self.position = Point(array(coords, 'd'))
 def fromRows(rows):
   """ rows: from a CSV file, as lists of strings. """
   return PointMatches([PointMatch(Point(array(imap(float, row[0:3]), 'd')),
                                   Point(array(imap(float, row[3:6]), 'd')))
                        for row in rows])
Exemplo n.º 6
0
'''
import sys, os
import cPickle as pickle
curDir = os.path.abspath(os.path.dirname(__file__))
sys.path.append("/plugin/mpicbg-master/mpicbg/target/mpicLatest.jar")
from mpicbg.models import Point, PointMatch, AffineModel3D, MovingLeastSquaresTransform

with open(os.path.join(curDir, "MLS",
                       "pointsToMatchDec2017EntryPointsB.pkl")) as fI:
    landmarkList = pickle.load(fI)
matches = []
for thisLand in landmarkList:
    for thisSide in ["right", "left", "centre"]:
        if "FROM_" + thisSide in thisLand and "TO_" + thisSide in thisLand:
            p1 = Point(map(float, thisLand["FROM_" + thisSide]))
            p2 = Point(map(float, thisLand["TO_" + thisSide]))
            matches.append(PointMatch(p1, p2, 1.0))

print len(matches), "landmark points used"

mls = MovingLeastSquaresTransform()
model = AffineModel3D()
mls.setModel(model)
mls.setMatches(matches)

with open(os.path.join(curDir, "MLS", "Points_input.pkl")) as fI:
    pointList = pickle.load(fI)
output = []
for i in range(len(pointList)):
    output.append(map(float, mls.apply(pointList[i])))