Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像配准-使用FORGE.NET框架(C#)的相位相关算法_C#_Algorithm_Image Processing_Fft_Aforge - Fatal编程技术网

图像配准-使用FORGE.NET框架(C#)的相位相关算法

图像配准-使用FORGE.NET框架(C#)的相位相关算法,c#,algorithm,image-processing,fft,aforge,C#,Algorithm,Image Processing,Fft,Aforge,我一直在用C#编写一个代码,用这个相位相关算法注册两幅图像之间的偏移(x,y轴),如维基百科所示: 为了帮助我做到这一点,我使用了一个org.NET框架的ComplexImage类及其快速傅立叶变换方法 代码如下所示: Bitmap fixed = (Bitmap)System.Drawing.Image.FromFile("Lenna.png"); Bitmap shifted = (Bitmap)System.Drawing.Image.FromFile("Lenna2.png");

我一直在用C#编写一个代码,用这个相位相关算法注册两幅图像之间的偏移(x,y轴),如维基百科所示:

为了帮助我做到这一点,我使用了一个org.NET框架的ComplexImage类及其快速傅立叶变换方法

代码如下所示:

 Bitmap fixed = (Bitmap)System.Drawing.Image.FromFile("Lenna.png");
 Bitmap shifted = (Bitmap)System.Drawing.Image.FromFile("Lenna2.png");

 //apply greyscale
 fixed = Grayscale.CommonAlgorithms.BT709.Apply(fixed);
 shifted = Grayscale.CommonAlgorithms.BT709.Apply(shifted);

 ComplexImage fixedCplx = ComplexImage.FromBitmap(fixed);
 int height = fixedCplx.Data.GetLength(0);
 int width  = fixedCplx.Data.GetLength(1);
 ComplexImage shiftedCplx = ComplexImage.FromBitmap(shifted);

 fixedCplx.ForwardFourierTransform();
 shiftedCplx.ForwardFourierTransform();

 for (int y = 0; y < height; y++)
 {
     for (int x = 0; x < width; x++)
     {
         //Calculating elementwise complex conjugate of the shifted image 2d vector
         shiftedCplx.Data[y, x].Im = -1 * shiftedCplx.Data[y, x].Im;
         //Elementwise multiplication to obtain cross power spectrum
         shiftedCplx.Data[y, x] = Complex.Multiply(fixedCplx.Data[y, x], shiftedCplx.Data[y, x]);
         //Elementwise normalization
         shiftedCplx.Data[y, x] = Complex.Divide(shiftedCplx.Data[y, x], shiftedCplx.Data[y, x].Magnitude);
     }
 }
 shiftedCplx.BackwardFourierTransform();
Bitmap fixed=(Bitmap)System.Drawing.Image.FromFile(“Lenna.png”);
位图移位=(位图)System.Drawing.Image.FromFile(“Lenna2.png”);
//应用灰度
fixed=灰度.CommonAlgorithms.BT709.Apply(固定);
移位=灰度.CommonAlgorithms.BT709.Apply(移位);
ComplexImage fixedclplx=ComplexImage.FromBitmap(固定);
int height=fixedclplx.Data.GetLength(0);
int width=fixedclplx.Data.GetLength(1);
ComplexImage shiftedCplx=ComplexImage.FromBitmap(移位);
fixedCplx.ForwardFourierTransform();
shiftedCplx.ForwardFourierTransform();
对于(int y=0;y
然而,在计算逆变换时应该出现的峰值函数并没有显示出来。。。我已经用维基百科链接上的图片进行了测试,但结果只得到了一张白色图片。上面显示的代码有什么问题吗

一些考虑:

  • 也许我不理解算法背后的数学原理。当取元素积[Ga].[Gb*]时,这个*符号是否意味着需要像我一直做的那样共轭矩阵的每个元素?还是矩阵的核心
  • 规范化[Ga].[Gb*]/|[Ga].[Gb*]|时,将每个矩阵元素(均为复数)除以其大小是否正确?我已经在我的代码中完成了这一点,正如预期的那样,在算法结束时,
    shiftedCplx.Data[]
    数组中的每个元素的大小都为1(这意味着此时的所有相关信息都是它们的相位)
看起来“BackwardFourierTransform()”函数并没有真正按照预期工作,或者在我处理数据的过程中出现了问题

编辑1

正如jaket在评论中指出的那样,刚刚编辑了代码


另外,我刚刚意识到一件事:当傅里叶变换灰度图像时,相应2D向量中的每个值的范围为0到255。对我来说,这意味着逆变换也会在该范围内产生一些值(即使数据事先进行了规范化),但我发现在这种情况下并非如此。
shiftedCplx.Data[,]
向量中的大多数元素在转换回空间域后的值都会大于255,当然,用它制作位图图像会创建一个几乎全白色的图像。在POC中,F*G不是矩阵的乘法,而是矩阵的元素生成

因此,它被称为哈达玛生产

在matlab中,该结果由“*”运算符操作

但是在Forge.net的复杂函数中,没有这样的操作,可能是

    // 푸리에 변환 한 이미지를 현실과 상상의 부분 분해
    Cv.Split (dft1, srcRe1, srcIm1, null , null );
    Cv.Split (dft2, srcRe2, srcIm2, null , null );

    for  ( int  I = 0; i <dft_M; i ++)
    {
        for  ( int  J = 0; j <dft_N; j ++)
        {
            // 이미지를  F × G *
            dstRe [i, j] = srcRe1 [i, j] * srcRe2 [i, j] - srcIm1 [i, j] * srcIm2 [i, j];
            dstIm [i, j] = srcRe1 [i, j] * srcIm2 [i, j + srcRe2 [i, j] * srcIm1 [i, j];

            // 절대 값을 계산하고 그 값으로 나누면 | F × G * |
            double  Spectrum = Math.Sqrt (dstRe [i, j] * dstRe [i, j + dstIm [i, j] * dstIm [i, j]);
            dstRe [i, j] = dstRe [i, j] / spectrum;
            dstIm [i, j] = dstIm [i, j] / spectrum;
        }
    }
    // 계산 결과를 통합
    Cv.Merge (dstRe, dstIm, null , null , result);
//푸리에 변환 한 이미지를 현실과 상상의 부분 분해
Cv.Split(dft1,srcRe1,srcIm1,null,null);
Cv.Split(dft2,srcRe2,srcIm2,null,null);

对于(inti=0;I,
imgTrslCpl.Data[y,x]
是如何定义的?对不起,这应该是
shiftedCplx.Data[y,x]
。在任何情况下,
ComplexImage.Data[]
定义为复杂类型结构的2D数组。
复杂类型结构具有存储复数实部和虚部以及幅值和相位的字段。方法包括
复杂类型结构的乘法()和
复杂类型结构的除法()
是的,我理解,我只是不知道imgTrslCpl是在哪里定义的,我想知道这是否与您的问题有关。使用前向FFT。