MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / np_sample

Function np_sample

tensorpack/dataflow/imgaug/deform.py:43–65  ·  view source on GitHub ↗
(img, coords)

Source from the content-addressed store, hash-verified

41
42
43def np_sample(img, coords):
44 # a numpy implementation of ImageSample layer
45 coords = np.maximum(coords, 0)
46 coords = np.minimum(coords, np.array([img.shape[0] - 1, img.shape[1] - 1]))
47
48 lcoor = np.floor(coords).astype('int32')
49 ucoor = lcoor + 1
50 ucoor = np.minimum(ucoor, np.array([img.shape[0] - 1, img.shape[1] - 1]))
51 diff = coords - lcoor
52 neg_diff = 1.0 - diff
53
54 lcoory, lcoorx = np.split(lcoor, 2, axis=2)
55 ucoory, ucoorx = np.split(ucoor, 2, axis=2)
56 diff = np.repeat(diff, 3, 2).reshape((diff.shape[0], diff.shape[1], 2, 3))
57 neg_diff = np.repeat(neg_diff, 3, 2).reshape((diff.shape[0], diff.shape[1], 2, 3))
58 diffy, diffx = np.split(diff, 2, axis=2)
59 ndiffy, ndiffx = np.split(neg_diff, 2, axis=2)
60
61 ret = img[lcoory, lcoorx, :] * ndiffx * ndiffy + \
62 img[ucoory, ucoorx, :] * diffx * diffy + \
63 img[lcoory, ucoorx, :] * ndiffy * diffx + \
64 img[ucoory, lcoorx, :] * diffy * ndiffx
65 return ret[:, :, 0, :]
66
67
68class GaussianDeform(ImageAugmentor):

Callers 1

_augmentMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…