Search in sources :

Example 1 with Mapping2D

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);
        }
    }
}
Also used : ImageProcessor(ij.process.ImageProcessor) Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) Mapping2D(imagingbook.pub.geometry.mappings.Mapping2D)

Aggregations

ImageProcessor (ij.process.ImageProcessor)1 Pnt2d (imagingbook.pub.geometry.basic.Pnt2d)1 Mapping2D (imagingbook.pub.geometry.mappings.Mapping2D)1