(img, coords)
| 41 | |
| 42 | |
| 43 | def 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 | |
| 68 | class GaussianDeform(ImageAugmentor): |
no outgoing calls
no test coverage detected
searching dependent graphs…