OpenCV 2.3 FFT的问题

时间:2011-09-12 20:43:42

标签: opencv fft

我想我在搞乱这里的东西。我正在尝试对图像执行FFT,

Here这是一个简单的图像并做一些填充将其转换为16x16图像。首先将图像调整为12x12,然后取log(img + 1)amd,然后将其填充为16x16。它本来是一个11x11的jpg。检查输出我确定填充是正确的,但为什么我在FFT之后得到这些巨大的(或非常微小的负值)值?

CV :: DFT(inputImage的[0],splittedImage [0],CV :: DFT_COMPLEX_OUTPUT);

仅显示第一个通道的第一行实数和虚数输出。这种情况发生在所有渠道上。

16 16 2 1102.98264 54.55353 -30.83002 -11.52413 0.91865 3.42735 1.56366 3.08065 4.32513 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000

0.00000 -9.31782 -29.86937 -18.65367 -8.81698 -0.44684 1.11674 -0.10631 0.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000 -6277438562204192200000000000000000000000000000000000000000000000000.00000

如果我在没有DFT_XXXX选项或cv :: DFT_ROWS的情况下进行FFT,我会得到以下内容

1102.98264 54.55353 -9.31782 -30.83002 -29.86937 -11.52413 -18.65367 0.91865 -8.81698 3.42735 -0.44684 1.56366 1.11674 3.08065 -0.10631 4.32513

我错过了cv :: DFT_XX ??

的标志

填充码

cv::Mat PadImage(cv::Mat inputImage, int padSize)
{

    cv::Mat paddedImage;
    paddedImage.create(inputImage.size().height+2*padSize, inputImage.size().width + 2*padSize, inputImage.type());

    int height = inputImage.size().height;
    int width = height;
    int paddedRow = padSize;
    int paddedCol = padSize;

    //copy original image to center of padded image
    for (int row = 0; row < height; row++)
    {
        for (int col = 0; col < width; col++)
        {
            paddedImage.at<cv::Vec3d>(row + paddedRow, col + paddedCol)[0] = inputImage.at<cv::Vec3d>(row, col)[0];
            paddedImage.at<cv::Vec3d>(row + paddedRow, col + paddedCol)[1] = inputImage.at<cv::Vec3d>(row, col)[1];
            paddedImage.at<cv::Vec3d>(row + paddedRow, col + paddedCol)[2] = inputImage.at<cv::Vec3d>(row, col)[2];
        }
    }

    // Pad top
    paddedRow -= 1;
    for (int row = 0; row < padSize; row++)
    {
        for (int col = 0; col < width; col++)
        {
            paddedImage.at<cv::Vec3d>(paddedRow, col + paddedCol)[0] = inputImage.at<cv::Vec3d>(row, col)[0];
            paddedImage.at<cv::Vec3d>(paddedRow, col + paddedCol)[1] = inputImage.at<cv::Vec3d>(row, col)[1];
            paddedImage.at<cv::Vec3d>(paddedRow, col + paddedCol)[2] = inputImage.at<cv::Vec3d>(row, col)[2];           
        }
        paddedRow--;
    }

    // Pad bottom           
    paddedRow = 2 * padSize - 1;
    for (int row = height - padSize; row < height; row++)
    {
        for (int col = 0; col < width; col++)
        {
            paddedImage.at<cv::Vec3d>(height + paddedRow, col + paddedCol)[0] = inputImage.at<cv::Vec3d>(row, col)[0];          
            paddedImage.at<cv::Vec3d>(height + paddedRow, col + paddedCol)[1] = inputImage.at<cv::Vec3d>(row, col)[1];          
            paddedImage.at<cv::Vec3d>(height + paddedRow, col + paddedCol)[2] = inputImage.at<cv::Vec3d>(row, col)[2];                      
        }
        paddedRow--;
    }

    // Pad left         
    paddedCol = padSize;
    paddedRow = padSize;
    for (int row = 0; row < height + 2 * padSize; row++)
    {

        for (int col = padSize; col <= 2*padSize; col++)
        {
            paddedImage.at<cv::Vec3d>(row, paddedCol)[0] = paddedImage.at<cv::Vec3d>(row, col)[0];                                              
            paddedImage.at<cv::Vec3d>(row, paddedCol)[1] = paddedImage.at<cv::Vec3d>(row, col)[1];                                                          
            paddedImage.at<cv::Vec3d>(row, paddedCol)[2] = paddedImage.at<cv::Vec3d>(row, col)[2];                                              
            paddedCol--;
        }
        paddedCol = padSize;
    }

    // Pad right         
    paddedCol = 2*padSize-1 + width;
    paddedRow = padSize;
    for (int row = 0; row < height + 2 * padSize; row++)
    {
        for (int col = width - padSize; col <= width+padSize; col++)
        {
            paddedImage.at<cv::Vec3d>(row, paddedCol)[0] = paddedImage.at<cv::Vec3d>(row, col)[0];                                  
            paddedImage.at<cv::Vec3d>(row, paddedCol)[1] = paddedImage.at<cv::Vec3d>(row, col)[1];                      
            paddedImage.at<cv::Vec3d>(row, paddedCol)[2] = paddedImage.at<cv::Vec3d>(row, col)[2];                      
            paddedCol--;            
        }
        paddedCol = 2*padSize-1 + width;
    }


    return paddedImage;
}

1 个答案:

答案 0 :(得分:1)

我的错误是我不得不推入双通道图像而不是单通道图像。我通过查看matlab并误导自己来翻译代码。