I am going to warp an image according to the user-defined function in Java. In general, the image is relatively large (JPEG, 30-50 MB).
Initially, the image is loaded:
BufferedImage img = ImageIO.read("image.jpg");
Suppose [X,Y] to be the resampled pixel coordinates of the image,where [x,y] represent its pixel coordinates.
The coordinate function is (a simple example) written as follows:
X = y * cos(x);
Y = x;
My idea is to use pixel-by-pixel transformation:
//Get size of the raster
int width = img.getWidth(), height = img.getHeight();
int proj_width = (int)(width * Math.cos(height*Math.pi/180)),proj_height = height;
//Create output image
BufferedImage img2 = new BufferedImage(proj_width+1, proj_height+1, img.getType());
//Reproject raster
for (int i = 0; i < img.getWidth(); i++) {
for (int j = 0; j < img.getHeight(); j++) {
//Color of the pixel
int col = img.getRGB(i, j);
//Its new coordinates
int X = (int)(i * Math.cos(j*Math.pi/180));
int Y = j;
//Set X,Y,col to the new raster
img2.setRGB(X,Y,col);
}
}
Is there any faster way to realize this operation without any additional library?
For example using the warpRect() method in the Warp class...
Thanks for your help.