use of imagingbook.pub.geometry.mappings.Mapping2D in project imagingbook-common by imagingbook.
the class ImageMapper method map.
// ---------------------------------------------------------------------
/**
* Transforms the source image to the target image using this geometric
* mapping and the specified pixel interpolation method.
* The two images are passed as instances of {@link ImageAccessor}.
* Note that source and target reference different images!
* The geometric mapping is supposed to be INVERTED, i.e. transforming
* target to source image coordinates!
*
* @param sourceAcc accessor to the source image
* @param targetAcc accessor to the target image
*/
public void map(ImageAccessor sourceAcc, ImageAccessor targetAcc) {
if (targetAcc.getProcessor() == sourceAcc.getProcessor()) {
throw new IllegalArgumentException("Source and target image must not be the same!");
}
// this always IS an inverse mapping!!
Mapping2D invMap = mapping;
ImageProcessor target = targetAcc.getProcessor();
final int w = target.getWidth();
final int h = target.getHeight();
for (int v = 0; v < h; v++) {
for (int u = 0; u < w; u++) {
Pnt2d sourcePt = invMap.applyTo(PntInt.from(u, v));
float[] val = sourceAcc.getPix(sourcePt.getX(), sourcePt.getY());
targetAcc.setPix(u, v, val);
}
}
}
Aggregations