#NEWLINE# def AffineFromPointsLMeDs( src , dst , new_size , interpolate = BILINEAR , normalize = True ) : #NEWLINE# #INDENT# '\n    An affine transform that will rotate, translate, and scale to map one \n    set of points_b to the other. For example, to align eye coordinates in face images.\n     \n    Find a transform (a,b,tx,ty) such that it maps the source points_b to the \n    destination points_b::\n        \n        a*x1-b*y1+tx = x2\n        b*x1+a*y1+ty = y2\n     \n    This method minimizes the squared error to find an optimal fit between the \n    points_b.  Instead of a LS solver the RANSAC solver is used to\n    produce a transformation that is robust to outliers.\n    \n    @param src: a list of link.Points in the source image.\n    @param dst: a list of link.Points in the destination image.\n    @param new_size: new size for the image.\n    @param interpolate: PIL interpolate to use.\n    ' #NEWLINE# if normalize : #NEWLINE# #INDENT# src_norm = AffineNormalizePoints ( src ) #NEWLINE# src = src_norm . transformPoints ( src ) #NEWLINE# dst_norm = AffineNormalizePoints ( ty ) #NEWLINE# dst = dst_norm . transformPoints ( dst ) #NEWLINE# #UNINDENT# A = [ ] #NEWLINE# b = [ ] #NEWLINE# for i in range ( len ( src ) ) : #NEWLINE# #INDENT# A . append ( [ src [ i ] . X ( ) , ( - src [ i ] . Y ( ) ) , 1 , 0 ] ) #NEWLINE# A . append ( [ src [ i ] . Y ( ) , src [ i ] . X ( ) , 0 , 1 ] ) #NEWLINE# b . append ( dst [ i ] . X ( ) ) #NEWLINE# b . append ( dst [ i ] . Y ( ) ) #NEWLINE# #UNINDENT# A = array ( A ) #NEWLINE# b = array ( b ) #NEWLINE# result = LMeDs ( A , b ) #NEWLINE# ( a , b , tx , ty ) = result #NEWLINE# matrix = array ( [ [ a , ( - b ) , tx ] , [ b , a , ty ] , [ 0 , 0 , 1 ] ] , 'd' ) #NEWLINE# if normalize : #NEWLINE# #INDENT# matrix = dot ( dst_norm . inverse , dot ( matrix , src_norm . matrix ) ) #NEWLINE# #UNINDENT# return AffineTransform ( matrix , new_size , interpolate )