use of imagingbook.lib.image.access.ImageAccessor in project imagingbook-common by imagingbook.
the class ImageExtractor method extractImage.
/**
* Fills the image {@code R} from the source image
* {@code I} (referenced by {@code this} object).
* The image {@code R} is extracted from a quadrilateral patch of the source image,
* defined by the transformation of the boundary of {@code R} by {@code T(x)}.
* Grayscale and color images my not be mixed (i.e., {@code R} must be of the same type as {@code I}).
* @param R the image to be filled.
* @param T a {@link LinearMapping2D} object.
*/
public void extractImage(ImageProcessor R, LinearMapping2D T) {
int prevInterpolationMethod = I.getInterpolationMethod();
// save current interpolation method
I.setInterpolationMethod(interpolationMethod);
ImageAccessor iaI = ImageAccessor.create(I);
ImageAccessor iaR = ImageAccessor.create(R);
int wT = R.getWidth();
int hT = R.getHeight();
for (int u = 0; u < wT; u++) {
for (int v = 0; v < hT; v++) {
Pnt2d uv = PntInt.from(u, v);
Pnt2d xy = T.applyTo(uv);
float[] val = iaI.getPix(xy.getX(), xy.getY());
iaR.setPix(u, v, val);
}
}
// restore interpolation method
I.setInterpolationMethod(prevInterpolationMethod);
}
Aggregations