简体   繁体   中英

Affine transform with interpolation

I would like to do an affine transformation on a very low resolution bitmap and I would like to do it while preserving the maximum amount of information.

My input data is a 1 bit 64-by-64 pixel image of hand written character and my output would be greyscale and higher resolution. Upon analysing the image I construct a series of affine transformations (rotation, scaling, shear, translation) what I could multiply into a single affine transformation matrix.

My problem is that given the input image and my computed affine transformation matrix , how can I calculate my output image in the highest possible quality? I have read articles about different interpolation techniques, but all of them are about how to do interpolation for scaling, and not for general affine transforms.

Here is a demo what is doing exactly what I am looking for. Given an affine transformation matrix and an interpolation technique it calculates an image.

http://bigwww.epfl.ch/demo/jaffine/index.html

Can you explain me what are the steps required for calculating a higher resolution (for example 4x) greyscale image, if I have a lower resolution 1-bit input and a given T affine transformation matrix?

Can you link me to some source code or tutorials or articles or possibly even books about how to implement a linear, cubic or better interpolation with affine transform?

I need to implement this problem in Java, and I know Java has an Affine class, but I don't know if it implements interpolation. Do you know any C++ or Java library what has nice to read code for figuring out how to write an algorithm for doing affine transform using interpolation?

Are there any freely available libraries for Java or C++ which have built-in functions for calculating affine transform using interpolation?

The same people you linked to have a C implementation with several interpolation options here . You could probably use JNI to wrap it. There is also JavaCV , which wraps OpenCV. OpenCV contains the warpAffine, which has interpolation. Also, check out the Java Advanced Imaging API here .

OK, here is the solution I ended up with.

  1. I transformed all my array[][] into a BufferedImage object

     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; } 
  2. Applied the affine transformation using AffineTransformOp with interpolation bicubic

      AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC); BufferedImage im_transformed = op.filter(im_src, null); 
  3. Transformed back the BufferedImage object into array[][]:

      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; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM