Guest User

Untitled

a guest
Aug 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment