带插值的仿射变换 [英] Affine transform with interpolation

查看:61
本文介绍了带插值的仿射变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个非常低分辨率的位图上进行仿射变换,并且希望在保留最大信息量的同时进行仿射变换.

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.

我的输入数据是一个手写字符的1位64×64像素图像,我的输出将是灰度和更高的分辨率.分析图像后,我构造了一系列仿射变换(旋转,缩放,剪切,平移),然后可以将它们乘以一个仿射变换矩阵.

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

如果我具有较低分辨率的1位输入和给定的T仿射变换矩阵,您能解释一下计算较高分辨率(例如4x)灰度图像所需的步骤吗?

您能否将我链接到某些 源代码 教程 文章 甚至可能还有 本书 关于如何通过仿射变换实现线性,三次或更优插值?

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?

我需要在Java中实现此问题,并且我知道Java具有Affine类,但是我不知道它是否实现插值.您是否知道任何C ++或Java库最适合阅读代码以弄清楚如何编写使用插值进行仿射变换的算法?

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?

是否有可用于Java或C ++的免费库,它们具有内置功能,可使用插值来计算仿射变换?

推荐答案

好的,这是我最终得到的解决方案.

OK, here is the solution I ended up with.

  1. 我将我所有的array [] []都转换为BufferedImage对象

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

  • 将AffineTransformOp应用于仿射变换并插值三次三次

  • 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);
    

  • 将BufferedImage对象转换回array [] []:

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

  • 这篇关于带插值的仿射变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆