The mapping from destination pixels to source positions is described by bilinear interpolation within a rectilinear grid of points with known mappings.
Given a destination pixel coordinate (x, y) that lies within a cell having corners at (x0, y0), (x1, y0), (x0, y1) and (x1, y1), with source coordinates defined at each respective corner equal to (sx0, sy0), (sx1, sy1), (sx2, sy2) and (sx3, sy3), the source position (sx, sy) that maps onto (x, y) is given by the formulas:
xfrac = (x - x0)/(x1 - x0) yfrac = (y - y0)/(y1 - y0) s = sx0 + (sx1 - sx0)*xfrac t = sy0 + (sy1 - sy0)*xfrac u = sx2 + (sx3 - sx2)*xfrac v = sy2 + (sy3 - sy2)*xfrac sx = s + (u - s)*yfrac sy = t + (v - t)*yfrac
In other words, the source x and y values are interpolated horizontally along the top and bottom edges of the grid cell, and the results are interpolated vertically:
(x0, y0) -> (x1, y0) -> (sx0, sy0) (sx1, sy1) +------------+---------+ | |\ | | | (s, t) | | | | | | | | | | | | | | (x, y) -> | | | (sx, sy)--+ | | | | | | | | | (u, v) | | |/ | +------------+---------+ (x0, y1) -> (x1, y1) -> (sx2, sy2) (sx3, sy3)
Points outside the bounds of the cells defining the grid warp will be mapped to the source image using the identity transformation.
WarpGrid is marked final so that it may be more easily inlined.
|
|
|
|