def crop_to_corner(img, corner, small_padding=1, large_padding=2):
 assert (corner in (0, 1, 2, 3)), 'specify corner 0, 1, 2, or 3'
 assert (img.shape[0] == img.shape[1]), 'img is not square'
 assert ((img.shape[0] % 2) == 0), 'even number of pixels assumption violated'
 half_size = (img.shape[0] / 2)
 big_ii = (0 if (corner in (0, 1)) else 1)
 big_jj = (0 if (corner in (0, 2)) else 1)
 tp = (small_padding + large_padding)
 return img[((big_ii * half_size) + tp):(((big_ii + 1) * half_size) - tp), ((big_jj * half_size) + tp):(((big_jj + 1) * half_size) - tp)]

def crop_to_corner ( img , corner , small_padding = 1 , large_padding = 2 ) : assert ( corner in ( 0 , 1 , 2 , 3 ) ) , 'specify corner 0, 1, 2, or 3' assert ( img . shape [ 0 ] == img . shape [ 1 ] ) , 'img is not square' assert ( ( img . shape [ 0 ] % 2 ) == 0 ) , 'even number of pixels assumption violated' half_size = ( img . shape [ 0 ] / 2 ) big_ii = ( 0 if ( corner in ( 0 , 1 ) ) else 1 ) big_jj = ( 0 if ( corner in ( 0 , 2 ) ) else 1 ) tp = ( small_padding + large_padding ) return img [ ( ( big_ii * half_size ) + tp ) : ( ( ( big_ii + 1 ) * half_size ) - tp ) , ( ( big_jj * half_size ) + tp ) : ( ( ( big_jj + 1 ) * half_size ) - tp ) ]
given an large image consisting of 3x3 squares with small_padding padding concatenated into a 2x2 grid with large_padding padding .