def obj_box_shift(<EOL>im, classes=None, coords=None, wrg=<NUM_LIT:0.1>, hrg=<NUM_LIT:0.1>, row_index=<NUM_LIT:0>, col_index=<NUM_LIT:1>, channel_index=<NUM_LIT:2>, fill_mode='<STR_LIT>',<EOL>cval=<NUM_LIT:0.>, order=<NUM_LIT:1>, is_rescale=False, is_center=False, is_random=False, thresh_wh=<NUM_LIT>, thresh_wh2=<NUM_LIT><EOL>):
if classes is None:<EOL><INDENT>classes = []<EOL><DEDENT>if coords is None:<EOL><INDENT>coords = []<EOL><DEDENT>imh, imw = im.shape[row_index], im.shape[col_index]<EOL>if (hrg >= <NUM_LIT:1.0>) and (hrg <= <NUM_LIT:0.>) and (wrg >= <NUM_LIT:1.0>) and (wrg <= <NUM_LIT:0.>):<EOL><INDENT>raise AssertionError("<STR_LIT>")<EOL><DEDENT>if is_random:<EOL><INDENT>tx = np.random.uniform(-hrg, hrg) * imh<EOL>ty = np.random.uniform(-wrg, wrg) * imw<EOL><DEDENT>else:<EOL><INDENT>tx, ty = hrg * imh, wrg * imw<EOL><DEDENT>translation_matrix = np.array([[<NUM_LIT:1>, <NUM_LIT:0>, tx], [<NUM_LIT:0>, <NUM_LIT:1>, ty], [<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>]])<EOL>transform_matrix = translation_matrix  <EOL>im_new = affine_transform(im, transform_matrix, channel_index, fill_mode, cval, order)<EOL>def _get_coord(coord):<EOL><INDENT>"""<STR_LIT>"""<EOL>if is_center:<EOL><INDENT>coord = obj_box_coord_centroid_to_upleft(coord)<EOL><DEDENT>x = coord[<NUM_LIT:0>] - ty  <EOL>y = coord[<NUM_LIT:1>] - tx  <EOL>w = coord[<NUM_LIT:2>]<EOL>h = coord[<NUM_LIT:3>]<EOL>if x < <NUM_LIT:0>:<EOL><INDENT>if x + w <= <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>w = w + x<EOL>x = <NUM_LIT:0><EOL><DEDENT>elif x > im_new.shape[<NUM_LIT:1>]:  <EOL><INDENT>return None<EOL><DEDENT>if y < <NUM_LIT:0>:<EOL><INDENT>if y + h <= <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>h = h + y<EOL>y = <NUM_LIT:0><EOL><DEDENT>elif y > im_new.shape[<NUM_LIT:0>]:  <EOL><INDENT>return None<EOL><DEDENT>if (x is not None) and (x + w > im_new.shape[<NUM_LIT:1>]):  <EOL><INDENT>w = im_new.shape[<NUM_LIT:1>] - x<EOL><DEDENT>if (y is not None) and (y + h > im_new.shape[<NUM_LIT:0>]):  <EOL><INDENT>h = im_new.shape[<NUM_LIT:0>] - y<EOL><DEDENT>if (w / (h + <NUM_LIT:1.>) > thresh_wh2) or (h / (w + <NUM_LIT:1.>) > thresh_wh2):  <EOL><INDENT>return None<EOL><DEDENT>if (w / (im_new.shape[<NUM_LIT:1>] * <NUM_LIT:1.>) < thresh_wh) or (h / (im_new.shape[<NUM_LIT:0>] * <NUM_LIT:1.>) <<EOL>thresh_wh):  <EOL><INDENT>return None<EOL><DEDENT>coord = [x, y, w, h]<EOL>if is_center:<EOL><INDENT>coord = obj_box_coord_upleft_to_centroid(coord)<EOL><DEDENT>return coord<EOL><DEDENT>coords_new = list()<EOL>classes_new = list()<EOL>for i, _ in enumerate(coords):<EOL><INDENT>coord = coords[i]<EOL>if len(coord) != <NUM_LIT:4>:<EOL><INDENT>raise AssertionError("<STR_LIT>")<EOL><DEDENT>if is_rescale:<EOL><INDENT>coord = obj_box_coord_scale_to_pixelunit(coord, im.shape)<EOL>coord = _get_coord(coord)<EOL>if coord is not None:<EOL><INDENT>coord = obj_box_coord_rescale(coord, im_new.shape)<EOL>coords_new.append(coord)<EOL>classes_new.append(classes[i])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>coord = _get_coord(coord)<EOL>if coord is not None:<EOL><INDENT>coords_new.append(coord)<EOL>classes_new.append(classes[i])<EOL><DEDENT><DEDENT><DEDENT>return im_new, classes_new, coords_new<EOL>
Shift an image randomly or non-randomly, and compute the new bounding box coordinates.
    Objects outside the cropped image will be removed.

    Parameters
    -----------
    im : numpy.array
        An image with dimension of [row, col, channel] (default).
    classes : list of int or None
        Class IDs.
    coords : list of list of 4 int/float or None
        Coordinates [[x, y, w, h], [x, y, w, h], ...]
    wrg, hrg row_index col_index channel_index is_random fill_mode cval and order : see ``tl.prepro.shift``.
    is_rescale : boolean
        Set to True, if the input coordinates are rescaled to [0, 1]. Default is False.
    is_center : boolean
        Set to True, if the x and y of coordinates are the centroid (i.e. darknet format). Default is False.
    thresh_wh : float
        Threshold, remove the box if its ratio of width(height) to image size less than the threshold.
    thresh_wh2 : float
        Threshold, remove the box if its ratio of width to height or vice verse higher than the threshold.


    Returns
    -------
    numpy.array
        A processed image
    list of int
        A list of classes
    list of list of 4 numbers
        A list of new bounding boxes.