Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Affine transform with interpolation
- static BufferedImage BImageFrom2DArray(float data[][]) {
- int width = data.length;
- int height = data[0].length;
- BufferedImage myimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- int value = (int) ((1f - data[x][y]) * 255f);
- myimage.setRGB(y, x, (value << 16) | (value << 8) | value);
- }
- }
- return myimage;
- }
- AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC);
- BufferedImage im_transformed = op.filter(im_src, null);
- static float[][] ArrayFromBImage(BufferedImage bimage, int width, int height) {
- int max_x = bimage.getWidth();
- int max_y = bimage.getHeight();
- float[][] array = new float[width][height];
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- float red, alpha, value;
- int color;
- if (x >= max_x || y >= max_y) {
- array[y][x] = 0;
- } else {
- color = bimage.getRGB(x, y);
- alpha = (color >> 24) & 0xFF;
- red = (color >> 16) & 0xFF;
- value = 1f - red / 255;
- if (alpha == 0) {
- array[y][x] = 0;
- } else {
- array[y][x] = value;
- }
- }
- }
- }
- return array;
- }
Add Comment
Please, Sign In to add comment