Javaのユーザー定義関数に従って画像をゆがめていきます。一般に、画像は比較的大きい (JPEG、30 ~ 50 MB)。
最初に、イメージがロードされます。
BufferedImage img = ImageIO.read("image.jpg");
[X,Y] が画像のリサンプリングされたピクセル座標であるとします。[x,y] はそのピクセル座標を表します。
座標関数は (簡単な例で) 次のように記述されます。
X = y * cos(x);
Y = x;
私の考えは、ピクセル単位の変換を使用することです:
//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);
}
}
ライブラリを追加せずにこの操作を実現するより速い方法はありますか?
たとえば、Warp クラスで warpRect() メソッドを使用すると...
ご協力いただきありがとうございます。