daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Aug 18th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Affine transform with interpolation
  2. static BufferedImage BImageFrom2DArray(float data[][]) {
  3.     int width = data.length;
  4.     int height = data[0].length;
  5.     BufferedImage myimage = new BufferedImage(width, height,  BufferedImage.TYPE_INT_RGB);
  6.     for (int x = 0; x < width; x++) {
  7.         for (int y = 0; y < height; y++) {
  8.             int value = (int) ((1f - data[x][y]) * 255f);
  9.             myimage.setRGB(y, x, (value << 16) | (value << 8) | value);
  10.         }
  11.     }
  12.     return myimage;
  13. }
  14.    
  15. AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC);
  16.     BufferedImage im_transformed = op.filter(im_src, null);
  17.    
  18. static float[][] ArrayFromBImage(BufferedImage bimage, int width, int height) {
  19.     int max_x = bimage.getWidth();
  20.     int max_y = bimage.getHeight();
  21.     float[][] array = new float[width][height];
  22.     for (int x = 0; x < width; x++) {
  23.         for (int y = 0; y < height; y++) {
  24.             float red, alpha, value;
  25.             int color;
  26.             if (x >= max_x || y >= max_y) {
  27.                 array[y][x] = 0;
  28.             } else {
  29.                 color = bimage.getRGB(x, y);
  30.                 alpha = (color >> 24) & 0xFF;
  31.                 red = (color >> 16) & 0xFF;
  32.                 value = 1f - red / 255;
  33.                 if (alpha == 0) {
  34.                     array[y][x] = 0;
  35.                 } else {
  36.                     array[y][x] = value;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     return array;
  42.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top