for single image only Args: image (numpy.Array): the reference array of shape HxWXC. size (Tuple[int, int]): a tuple with the height and width that will be used to resize the extracted patches. Returns: cropped_image tform: 3x3 affine matrix
(image, center, bboxsize, crop_size)
| 31 | return center, size |
| 32 | |
| 33 | def crop_array(image, center, bboxsize, crop_size): |
| 34 | ''' for single image only |
| 35 | Args: |
| 36 | image (numpy.Array): the reference array of shape HxWXC. |
| 37 | size (Tuple[int, int]): a tuple with the height and width that will be |
| 38 | used to resize the extracted patches. |
| 39 | Returns: |
| 40 | cropped_image |
| 41 | tform: 3x3 affine matrix |
| 42 | ''' |
| 43 | # points: top-left, top-right, bottom-right |
| 44 | src_pts = np.array([ |
| 45 | [center[0]-bboxsize/2, center[1]-bboxsize/2], |
| 46 | [center[0] + bboxsize/2, center[1]-bboxsize/2], |
| 47 | [center[0]+bboxsize/2, center[1]+bboxsize/2]]) |
| 48 | DST_PTS = np.array([[0,0], [crop_size - 1, 0], [crop_size - 1, crop_size - 1]]) |
| 49 | |
| 50 | # estimate transformation between points |
| 51 | tform = estimate_transform('similarity', src_pts, DST_PTS) |
| 52 | |
| 53 | # warp images |
| 54 | cropped_image = warp(image, tform.inverse, output_shape=(crop_size, crop_size)) |
| 55 | |
| 56 | return cropped_image, tform.params.T |
| 57 | |
| 58 | class Cropper(object): |
| 59 | def __init__(self, crop_size, scale=[1,1], trans_scale = 0.): |