MCPcopy Create free account
hub / github.com/Pixel-Talk/EHM-Tracker / crop_array

Function crop_array

src/modules/pixie/utils/array_cropper.py:33–56  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

31 return center, size
32
33def 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
58class Cropper(object):
59 def __init__(self, crop_size, scale=[1,1], trans_scale = 0.):

Callers 1

cropMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected