Android图片注册

时间:2017-05-31 10:19:25

标签: java android fft registration cross-correlation

我必须为图像注册创建一个Android应用程序。我在裁剪图像后为每个图像创建了一个2D数组,并使用jtrasform创建了一个fft,然后我尝试创建一个互相关矩阵。在这个矩阵中搜索最大值坐标我期望具有用于移动我的图像的X e Y值,但是这个值是错误的,我无法找到错误。

public void Registration(Bitmap image,Bitmap image2) {
int square,x,y;
int Min2,Min1,Min;
Min1=min(image.getHeight(),image2.getHeight());
Min2=min(image.getWidth(),image2.getWidth());
if(Min1<Min2)
    Min=Min1;
else
    Min=Min2;

    if (Min>1024)
    square =1024;
    else{
        if (Min>512)
            square =512;

            else{
                if (Min<256)
                    square=128;


                else
                    square=256;
                    }}
Bitmap crop=Bitmap.createBitmap(image, 0,0,square, square);
Bitmap crop2=Bitmap.createBitmap(image2, 0,0,square, square);*/


float[][] array = new float[square-1][square-1];
float[][] array2 = new float[square-1][square-1];
float[][] array3 = new float[square-1][square-1];

for (x = 0; x < square-1; x++) {
        int p = crop.getPixel(x,x);
        int p1=crop2.getPixel(x,x);
        array[x][x] = (Color.red(p) + Color.green(p) + Color.blue(p)) / 3;
        array2[x][x] = (Color.red(p1) + Color.green(p1) + Color.blue(p1)) / 3;
    }
    for (y = square-1; y < (2*square)-1; y++) {
        for (x = 0; x < square-1; x++){
            array[x][y] = 0;
            array2[x][y] = 0;
    }}

FloatFFT_2D a = new FloatFFT_2D(square,square);
FloatFFT_2D b = new FloatFFT_2D(square,square);
a.complexForward(array);
b.complexForward(array2);
for (y = 0; y < (2*square)-1; y++) {
    for (x = 0; x < square-1; x++){
      if(y>=square){
          array2[x][y] =-array2[x][y];}

array3[x][y]=array[x][y]*array2[x][y];}}


FloatFFT_2D c = new FloatFFT_2D(square-1,square-1);
c.complexInverse(array3,false);

Max(array3,(square),(2*square));

0 个答案:

没有答案