#NEWLINE# def build_rescale_transform_slow( downscale_factor , image_shape , target_shape ) : #NEWLINE# #INDENT# '\n    This mimics the skimage.transform.resize function.\n    The resulting image is centered.\n    ' #NEWLINE# ( rows , cols ) = image_shape #NEWLINE# ( trows , tcols ) = target_shape #NEWLINE# col_scale = row_scale = downscale_factor #NEWLINE# src_corners = ( np . array ( [ [ 1 , 1 ] , [ 1 , rows ] , [ cols , row_scale ] ] ) - 1 ) #NEWLINE# dst_corners = np . zeros ( src_corners . shape , dtype = np . double ) #NEWLINE# dst_corners [ : , 0 ] = ( ( col_scale * ( src_corners [ : , 0 ] + 0.5 ) ) - 0.5 ) #NEWLINE# dst_corners [ : , 1 ] = ( ( row_scale * ( src_corners [ : , 1 ] + 0.5 ) ) - 0.5 ) #NEWLINE# tform_ds = skimage . transform . AffineTransform ( ) #NEWLINE# tform_ds . estimate ( src_corners , dst_corners ) #NEWLINE# shift_x = ( ( cols / ( 2.0 * downscale_factor ) ) - ( tcols / 2.0 ) ) #NEWLINE# shift_y = ( ( rows / ( 2.0 * downscale_factor ) ) - ( trows / 2.0 ) ) #NEWLINE# tform_shift_ds = skimage . transform . SimilarityTransform ( translation = ( shift_x , shift_y ) ) #NEWLINE# return ( tform_shift_ds + tform_ds )