def rigid_alignment(faces, path, plotflag=False):
 refpoints = faces.values()[0]
 for face in faces:
  points = faces[face]
  (R, tx, ty) = compute_rigid_transform(refpoints, points)
  T = array([[R[1][1], R[1][0]], [R[0][1], R[0][0]]])
  im = array(Image.open(os.path.join(path, face)))
  im2 = zeros(im.shape, 'uint8')
  for i in range(len(im.shape)):
   im2[:, :, i] = ndimage.affine_transform(im[:, :, i], linalg.inv(T), offset=[(- ty), (- tx)])
  if plotflag:
   imshow(im2)
   show()
  (h, w) = im2.shape[:2]
  border = ((w + h) / 20)
  imsave(os.path.join(path, ('aligned/' + face)), im2[border:(h - border), border:(w - border), :])

def rigid_alignment ( faces , path , plotflag = False ) : refpoints = faces . values ( ) [ 0 ] for face in faces : points = faces [ face ] ( R , tx , ty ) = compute_rigid_transform ( refpoints , points ) T = array ( [ [ R [ 1 ] [ 1 ] , R [ 1 ] [ 0 ] ] , [ R [ 0 ] [ 1 ] , R [ 0 ] [ 0 ] ] ] ) im = array ( Image . open ( os . path . join ( path , face ) ) ) im2 = zeros ( im . shape , 'uint8' ) for i in range ( len ( im . shape ) ) : im2 [ : , : , i ] = ndimage . affine_transform ( im [ : , : , i ] , linalg . inv ( T ) , offset = [ ( - ty ) , ( - tx ) ] ) if plotflag : imshow ( im2 ) show ( ) ( h , w ) = im2 . shape [ : 2 ] border = ( ( w + h ) / 20 ) imsave ( os . path . join ( path , ( 'aligned/' + face ) ) , im2 [ border : ( h - border ) , border : ( w - border ) , : ] )
align images rigidly and save as new images .