def sliceTest(big): nr, nc = np.shape(big) for i in range(nr): for j in range(nc): print i, j print slice(big, 3, Vector(j, i)) print slice(big, 5, Vector(j, i))
def calcNormRotate( self, shape ): xDiff = shape.shapePoints[self.rightEyeIx].x - shape.shapePoints[self.leftEyeIx].x yDiff = shape.shapePoints[self.rightEyeIx].y - shape.shapePoints[self.leftEyeIx].y p0 = [ xDiff, yDiff ] axisVector = [ 1, 0 ] thetaP = Vector.angleBetween( p0, axisVector ) thetaRot = thetaP rot = Vector.calcSRotMat( 1, thetaRot ) return rot, thetaRot
def calcNormRotate(self, shape): xDiff = shape.shapePoints[self.rightEyeIx].x - shape.shapePoints[ self.leftEyeIx].x yDiff = shape.shapePoints[self.rightEyeIx].y - shape.shapePoints[ self.leftEyeIx].y p0 = [xDiff, yDiff] axisVector = [1, 0] thetaP = Vector.angleBetween(p0, axisVector) thetaRot = thetaP rot = Vector.calcSRotMat(1, thetaRot) return rot, thetaRot
def __init__(self, pointList): self.shapePoints = [] # Add points to shape if isinstance(pointList[0], list): for [x, y] in pointList: self.shapePoints.append(Vector(x, y)) elif isinstance(pointList[0], tuple): for (x, y) in pointList: self.shapePoints.append(Vector(x, y)) else: self.shapePoints = pointList
def coordOffset( pt, n ): y = pt.y #row x = pt.x #col v = Vector.unit( [[ x - ( n - 1) / 2],[ y - ( n - 1 )/ 2 ] ]) # print type(v) #print "CoordOff: %f %f" % (v[0], v[1]) return v
def getGradient(pt, img): if pt.x is np.nan or pt.y is np.nan: return ## Check bounds h, w = np.shape(img) if pt.y > h - 2: pt.setY(h - 2) if pt.x > w - 2: pt.setX(w - 2) if pt.x < 1: pt.setX(1) if pt.y < 1: pt.setY(1) delF = [(img[pt.y, pt.x + 1] - img[pt.y, pt.x - 1]) / 2, (img[pt.y + 1, pt.x] - img[pt.y - 1, pt.x]) / 2] #print delF mag = math.sqrt(delF[0]**2 + delF[1]**2) unitF = Vector.unit(delF) return unitF, mag, pt
def readInASM(self, asm): allLines = None #f = "C:\\Users\\Valerie\\Documents\\Visual Studio 2013\\Projects\\ActiveShapeModels\\ActiveShapeModels\\outputs\\outfile-ASM-100iters-500tr.txt" with open( os.path.join( self.output, 'outfile-ASM-%diters-%dtr.txt' % (self.nIters, self.nTrain)), "r") as infile: #with open( f, "r") as infile: allLines = infile.readlines() cleanLines = map(lambda x: x.strip().split(), allLines) s = [] for tuple in cleanLines: if tuple[0] == '!!!': if s != []: asm.meanShape = ActiveShape(s) s = [] else: pass elif tuple[0] == '@@@': if s != []: asm.addShape(ActiveShape(s)) s = [] else: pass else: s.append(Vector(float(tuple[0]), float(tuple[1]))) return asm
def calcMeanShape(self): xList = [el.xs for el in self.allShapes] yList = [el.ys for el in self.allShapes] meanPointsList = map(lambda x, y: Vector(x, y), np.mean(xList, 0), np.mean(yList, 0)) # meanPointsList = zip( np.mean(xList, 0), np.mean(yList, 0) ) return ActiveShape(meanPointsList)
def matIxs( n ): rows, cols = np.indices( (n,n) ) row = rows.flatten() col = cols.flatten() return map( lambda x: Vector( x[0], x[1] ), zip( row, col ) )