开发者

Problem with OpenCV 2.3 FFT

开发者 https://www.devze.com 2023-04-04 04:10 出处:网络
I guess I am messing up something here. I am trying to perform an FFT on an image, Which is a simple image and do some padding to turn it into a 16x16 image. First the image is resized to 12x12 and

I guess I am messing up something here. I am trying to perform an FFT on an image,

Problem with OpenCV 2.3 FFT

Which is a simple image and do some padding to turn it into a 16x16 image. First the image is resized to 12x12 and then take log(img+1) amd then pad it to make it 16x16. its originally a 11x11 jpg. Checking the outputs I am sure that the padding is correct but why am I getting these huge (or very tiny on a minus) values after the FFT?

cv::dft(inputImage[0],splittedImage[0],cv::DFT_COMPLEX_OUTPUT);

Showing only the first row of real and imaginary outputs for first channel. This happens on all channels.

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

If I do the FFT with no DFT_XXXX options or cv::DFT_ROWS I get the following

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

Am I missing a flag for cv::DFT_XX ??

Padding code

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<开发者_C百科;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;
}


My mistake was that I had to push in a dual channel image instead of a single channel image. I was translating code by looking at matlab and mislead myself.

0

精彩评论

暂无评论...
验证码 换一张
取 消