@@ -1579,7 +1579,8 @@ def super_resolution(clip, model_filename, epoch=0, up_scale=2, block_w=128, blo
15791579            Default is {}. 
15801580
15811581        pad_mode: (str) Padding type of NumPy to use. 
1582-             Default is "symmetric" 
1582+             If set to "source", the pixels in the source image will be used. 
1583+             Default is "source" 
15831584
15841585        framework: (str, 'MXNet' or 'TensorFlow') Deep learning framework to use. 
15851586            Defaut is 'MXNet'. 
@@ -1747,13 +1748,13 @@ def super_resolution_core(img, runner, up_scale=2, block_size=None, pad=None, cr
17471748            If TensorFlow framework is used, then it specifies the session. 
17481749            If MXNet framework is used, then it specifies the model. 
17491750
1750-     The default padding tymode  is set to 'symmetric '. 
1751+     The default padding mode  is set to 'source '. 
17511752    For detailed documentation, please refer to the documentation of "super_resolution" funcion in current library. 
17521753    """ 
17531754
17541755    # initialization 
17551756    if  pad_mode  is  None :
1756-         pad_mode  =  'symmetric ' 
1757+         pad_mode  =  'source ' 
17571758
17581759    if  data_format  is  None :
17591760        data_format  =  'NCHW' 
@@ -1794,24 +1795,49 @@ def super_resolution_core(img, runner, up_scale=2, block_size=None, pad=None, cr
17941795    # patch-wise processing 
17951796    for  i  in  range (math .ceil (h  /  block_size [0 ])):
17961797        for  j  in  range (math .ceil (w  /  block_size [1 ])):
1797- 
17981798            top  =  i  *  block_size [0 ]
17991799            bottom  =  min (h , (i  +  1 ) *  block_size [0 ])
18001800            left  =  j  *  block_size [1 ]
18011801            right  =  min (w , (j  +  1 ) *  block_size [1 ])
18021802
1803-             if  data_format  ==  'NCHW' :
1804-                 h_in  =  img [:, :, top :bottom , left :right ]
1805-             else :
1806-                 h_in  =  img [:, top :bottom , left :right , :]
1803+             if  pad_mode .lower () ==  'source'  and  pad  is  not None : # use "source" padding 
1804+ 
1805+                 padded_top  =  max (0 , top  -  pad [0 ])
1806+                 padded_bottom  =  min (h , bottom  +  pad [1 ])
1807+                 padded_left  =  max (0 , left  -  pad [2 ])
1808+                 padded_right  =  min (w , right  +  pad [1 ])
1809+ 
1810+                 if  data_format  ==  'NCHW' :
1811+                     h_in  =  img [:, :, padded_top :padded_bottom , padded_left :padded_right ]
1812+                     if  ((top  -  padded_top  !=  pad [0 ]) or  (padded_bottom  -  bottom  !=  pad [1 ])
1813+                         or  (left  -  padded_left  !=  pad [2 ]) or  (padded_right  -  right  !=  pad [3 ])):
1814+ 
1815+                         pad_width  =  ((0 , 0 ), (0 , 0 ), (pad [0 ] -  top  +  padded_top , pad [1 ] -  padded_bottom  +  bottom ), 
1816+                             (pad [2 ] -  left  +  padded_left , pad [3 ] -  padded_right  +  right ))
1817+                         h_in  =  np .pad (h_in , mode = 'symmetric' , pad_width = pad_width )
1818+                 else :
1819+                     h_in  =  img [:, padded_top :padded_bottom , padded_left :padded_right , :]
1820+                     if  ((top  -  padded_top  !=  pad [0 ]) or  (padded_bottom  -  bottom  !=  pad [1 ])
1821+                         or  (left  -  padded_left  !=  pad [2 ]) or  (padded_right  -  right  !=  pad [3 ])):
1822+ 
1823+                         pad_width  =  ((0 , 0 ), (pad [0 ] -  top  +  padded_top , pad [1 ] -  padded_bottom  +  bottom ), 
1824+                             (pad [2 ] -  left  +  padded_left , pad [3 ] -  padded_right  +  eright ), (0 , 0 ))
1825+                         h_in  =  np .pad (h_in , mode = 'symmetric' , pad_width = pad_width )
1826+ 
1827+             else : # use NumPy's padding 
18071828
1808-             # pre-padding 
1809-             if  pad  is  not None :
18101829                if  data_format  ==  'NCHW' :
1811-                     pad_width  =  (( 0 ,  0 ), ( 0 ,  0 ), ( pad [ 0 ],  pad [ 1 ]), ( pad [ 2 ],  pad [ 3 ])) 
1830+                     h_in  =  img [:, :,  top : bottom ,  left : right ] 
18121831                else :
1813-                     pad_width  =  ((0 , 0 ), (pad [0 ], pad [1 ]), (pad [2 ], pad [3 ]), (0 , 0 ))
1814-                 h_in  =  np .pad (h_in , mode = pad_mode , pad_width = pad_width )
1832+                     h_in  =  img [:, top :bottom , left :right , :]
1833+ 
1834+                 # pre-padding 
1835+                 if  pad  is  not None :
1836+                     if  data_format  ==  'NCHW' :
1837+                         pad_width  =  ((0 , 0 ), (0 , 0 ), (pad [0 ], pad [1 ]), (pad [2 ], pad [3 ]))
1838+                     else :
1839+                         pad_width  =  ((0 , 0 ), (pad [0 ], pad [1 ]), (pad [2 ], pad [3 ]), (0 , 0 ))
1840+                     h_in  =  np .pad (h_in , mode = pad_mode , pad_width = pad_width )
18151841
18161842            # forward 
18171843            if  framework  ==  'mxnet' :
0 commit comments