#NEWLINE# def main( img ) : #NEWLINE# #INDENT# 'Applies static transformations to img and plots for visual comparison' #NEWLINE# hw = ( img . shape [ 0 ] , img . shape [ 1 ] ) #NEWLINE# crop_percentage = 0.1 #NEWLINE# crop_hw = ( ( hw [ 0 ] - int ( ( hw [ 0 ] * crop_percentage ) ) ) , ( hw [ 1 ] - int ( ( hw [ 1 ] * crop_percentage ) ) ) ) #NEWLINE# augmentation_params = dict ( rotation = 45 , zoom = ( 0.5 , 2.0 ) , shear = 15 , translation = ( int ( ( hw [ 0 ] * 0.1 ) ) , ( - int ( ( hw [ 1 ] * 0.2 ) ) ) ) , flip_lr = True , flip_ud = True ) #NEWLINE# nAugmentations = len ( augmentation_params ) #NEWLINE# nPlots = ( nAugmentations + 3 ) #NEWLINE# nrows = int ( np . ceil ( np . sqrt ( nPlots ) ) ) #NEWLINE# ncols = int ( np . ceil ( ( nPlots / float ( nrows ) ) ) ) #NEWLINE# ( fig , axes ) = plt . subplots ( nrows = nrows , ncols = ncols , figsize = ( 16 , 12 ) ) #NEWLINE# axes = axes . flatten ( ) #NEWLINE# axes [ 0 ] . imshow ( img ) #NEWLINE# axes [ 0 ] . set_title ( 'Original Image' ) #NEWLINE# for ( it , ( key , param ) ) in enumerate ( augmentation_params . iteritems ( ) ) : #NEWLINE# #INDENT# ax = axes [ ( it + 1 ) ] #NEWLINE# augmentation_param = { #NEWLINE# #INDENT# key : param , #NEWLINE# #UNINDENT# } #NEWLINE# img_wf = dtf . transform_image ( img , ** augmentation_param ) #NEWLINE# ax . imshow ( img_wf . astype ( np . uint8 ) ) #NEWLINE# ax . set_title ( ( 'Augmentation Param: %s = %s' % ( key , param ) ) ) #NEWLINE# ax . set_xticks ( [ ] ) #NEWLINE# ax . set_yticks ( [ ] ) #NEWLINE# #UNINDENT# ax = axes [ ( it + 2 ) ] #NEWLINE# img_wf_og = dtf . transform_image ( img , ** augmentation_params ) #NEWLINE# ax . imshow ( img_wf_og . astype ( np . uint8 ) ) #NEWLINE# ax . set_title ( 'All Augmentations' ) #NEWLINE# ax . set_xticks ( [ ] ) #NEWLINE# ax . set_yticks ( [ ] ) #NEWLINE# ax = axes [ ( it + 3 ) ] #NEWLINE# img_wf = dtf . transform_image ( img , output_shape = crop_hw , ** augmentation_params ) #NEWLINE# ax . imshow ( img_wf . astype ( np . uint8 ) ) #NEWLINE# ax . set_title ( 'All Augmentation + Crop' )