#NEWLINE# def build_ds_transform( ds_factor = 1.0 , orig_size = ( 424 , 424 ) , target_size = ( 53 , 53 ) , do_shift = True , subpixel_shift = False ) : #NEWLINE# #INDENT# "\n    This version is a bit more 'correct', it mimics the skimage.transform.resize function.\n    " #NEWLINE# ( rows , cols ) = orig_size #NEWLINE# ( trows , tcols ) = target_size #NEWLINE# col_scale = row_scale = ds_factor #NEWLINE# src_corners = ( np . array ( [ [ 1 , 1 ] , [ 1 , rows ] , [ cols , rows ] ] ) - 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# if do_shift : #NEWLINE# #INDENT# if subpixel_shift : #NEWLINE# #INDENT# cols = ( ( cols // int ( ds_factor ) ) * int ( ds_factor ) ) #NEWLINE# rows = ( ( rows // int ( ds_factor ) ) * int ( ds_factor ) ) #NEWLINE# #UNINDENT# shift_x = ( ( cols / ( 2 * ds_factor ) ) - ( tcols / 2.0 ) ) #NEWLINE# shift_y = ( ( rows / ( 2 * ds_factor ) ) - ( trows / 2.0 ) ) #NEWLINE# tform_shift_ds = skimage . transform . SimilarityTransform ( translation = ( shift_x , shift_y ) ) #NEWLINE# return ( tform_shift_ds + tform_ds ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return tform_ds