#NEWLINE# def extract_image_patch( chunk_dst , img ) : #NEWLINE# #INDENT# '\n    extract a correctly sized patch from img and place it into chunk_dst,\n    which assumed to be preinitialized to zeros.\n    ' #NEWLINE# ( p_x , p_y ) = chunk_dst . shape #NEWLINE# ( im_x , im_y ) = img . shape #NEWLINE# offset_x = ( ( im_x - p_x ) // 2 ) #NEWLINE# offset_y = ( ( im_y - p_y ) // 2 ) #NEWLINE# if ( offset_x < 0 ) : #NEWLINE# #INDENT# cx = slice ( ( - offset_x ) , ( ( - offset_x ) + im_x ) ) #NEWLINE# ix = slice ( 0 , im_x ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cx = slice ( 0 , p_x ) #NEWLINE# ix = slice ( offset_x , ( offset_x + p_x ) ) #NEWLINE# #UNINDENT# if ( offset_y < 0 ) : #NEWLINE# #INDENT# cy = slice ( ( - offset_y ) , ( ( - offset_y ) + im_y ) ) #NEWLINE# iy = slice ( 0 , im_y ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cy = slice ( 0 , p_y ) #NEWLINE# iy = slice ( offset_y , ( offset_y + p_y ) ) #NEWLINE# #UNINDENT# chunk_dst [ ( cx , cy ) ] = uint_to_float ( img [ ( ix , iy ) ] )