def get_selection_rect(img, sr, target):
 left_border = ((abs((sr.left() - target.left())) / target.width()) * img.width())
 top_border = ((abs((sr.top() - target.top())) / target.height()) * img.height())
 right_border = ((abs((target.right() - sr.right())) / target.width()) * img.width())
 bottom_border = ((abs((target.bottom() - sr.bottom())) / target.height()) * img.height())
 return (left_border, top_border, ((img.width() - left_border) - right_border), ((img.height() - top_border) - bottom_border))

def get_selection_rect ( img , sr , target ) : left_border = ( ( abs ( ( sr . left ( ) - target . left ( ) ) ) / target . width ( ) ) * img . width ( ) ) top_border = ( ( abs ( ( sr . top ( ) - target . top ( ) ) ) / target . height ( ) ) * img . height ( ) ) right_border = ( ( abs ( ( target . right ( ) - sr . right ( ) ) ) / target . width ( ) ) * img . width ( ) ) bottom_border = ( ( abs ( ( target . bottom ( ) - sr . bottom ( ) ) ) / target . height ( ) ) * img . height ( ) ) return ( left_border , top_border , ( ( img . width ( ) - left_border ) - right_border ) , ( ( img . height ( ) - top_border ) - bottom_border ) )
given selection rect return the corresponding rectangle in the underlying image as left .