Deep-ML | Elastic Deformations: Random Displacements on a 3 by 3 Grid, Bicubic InterpolationElastic Deformations: Random Displacements on a 3 by 3 Grid, Bicubic Interpolation
Elastic Deformations: Random Displacements on a 3 by 3 Grid, Bicubic Interpolation
At the nine node positions the field equals the node values. Between them, cubic convolution weights the four nearest nodes along each axis by -0.0625, 0.5625, 0.5625 and -0.0625, reusing edge nodes beyond the grid, so the field bends smoothly through the nodes.
U-Net's key augmentation is a random smooth deformation of each training image: random displacement vectors on a coarse 3×3 grid, drawn from a Gaussian with a standard deviation of 10 pixels, are interpolated to a displacement for every pixel with bicubic interpolation. Implement the three parts.
random_grid(rng, sigma=10.0)
Return rng.normal(0.0, sigma, size=(2, 3, 3)), exactly this one call. grid[0] holds the row displacements Δy and grid[1] the column displacements Δx at the nodes; grid[c][i][j] is node row i, node column j.
displacement_field(grid, H, W) returns an array of shape (2,H,W) (with H,W≥2).
Node (i,j) sits at pixel row i(H−1)/2 and pixel column j(W−1)/2, so the nodes are at the corners, the edge midpoints and the centre.
Interpolate separably with cubic convolution. In grid units, pixel row y is at u=2y/(H−1) (and column x at v=2x/(W−1)). With the kernel (a=−0.5)
k(t)=⎩⎨⎧(a+2)∣t∣3−(a+3)∣t∣2+1a∣t∣3−5a∣t∣2+8a∣t∣−4a0∣t∣≤11<∣t∣<2otherwise,
the value at (u,v) is ∑m∑qk(u−m)k(v−q)g[mˉ,qˉ] over m=⌊u⌋−1,…,⌊u⌋+2 and q=⌊v⌋−1,…,⌊v⌋+2, where mˉ is m clamped to {0,1,2} (nodes beyond the grid repeat the edge node).
elastic_warp(image, grid, order=1) returns the deformed (H,W) image.
Output pixel (y,x) takes the input value at (y+Δy(y,x),x+Δx(y,x)), with the row coordinate clamped to [0,H−1] and the column coordinate to [0,W−1].
order=1 (images): bilinear interpolation between the four surrounding pixels.
order=0 (label maps): the nearest pixel, rounding halves up (⌊s+0.5⌋).