Map a rectangular area from one raster into another, with an arbitrary transformation (scale, translation, rotation) inbetween.
More...
Map a rectangular area from one raster into another, with an arbitrary transformation (scale, translation, rotation) inbetween.
Can be used to scale/transform images or other pixel/cell-based structures (grid maps).
The transformation is initialized with the transformation parameters and provides an iterator over the mapping. The iterator iterates over all pairs of correspondent source/target cell pairs in the raster mapping. The cell coordinates in the source and target raster are returned by the iterator's methods.
Example code: scale image to half size and rotate around center
double scale = 0.5;
tgt = 0;
Rect2i(0,0,tgt.width(),tgt.height()),
Point2d(src.width()/2,src.height()/2),
Point2d(tgt.width()/2,tgt.height()/2),
scale,
boost::math::constants::half_pi<double>(),
true);
for(RasterTransformation::iterator it = rt.begin(); it.isValid(); ++it)
{
if (src(it.srcX(), it.srcY()) > tgt(it.tgtX(), it.tgtY()))
tgt(it.tgtX(), it.tgtY()) = src(it.srcX(), it.srcY());
}
The focus in the implementation is more on speed than on high precision, therefore there is no such thing as interpolation, and source/target cells returned are matching (overlapping), but are not necessarily the ones with the largest overlap.
Properties of the cell coordinates returned by the iterator:
- The coordinates never point outside the specified source or target area (no additional check is required to avoid access beyond this area). Area interval is [LL, UR) - the lower left corner is inside, the upper right corner is outside.
- The outermost lines of the source/target areas may but are not guaranteed to be hit by the iterator (outer borders are a bit fuzzy in this regard)
- Source and target cells overlap (taking into regard the specified transformation), i.e. the intersection is not empty. Note: In very rare cases source and target cells do not overlap, (but are very close to touching each other at least). This results from floating point precision issues.
- The target area is always densely covered - there are no gaps/holes in the target area (inside the overlap area regarding the transformation).
- If the 'dense' parameter is set to false (default), the source area can have gaps. However, there are only single cell gaps, i.e. no two adjacent source cells are missed (inside the overlap area regarding the transformation). If the 'dense' parameter is set to true, no single cell is missed, but the number of steps for iteration over the transformation increases by 2 (the sampling raster is narrowed by factor sqrt(2) in both x and y direction).