1

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

Here 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<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;
}
10
  • Could you also post your code for making padding? Otherwise it is not clear how to reproduce your results. Commented Sep 12, 2011 at 21:00
  • @Andrey, just posted the code. Commented Sep 12, 2011 at 21:04
  • But how are you getting 16x16 image from 11x11 image with this code? Your padding function adds a symmetric padding and can make only 15x15 or 17x17 image. Am I missed something? Commented Sep 12, 2011 at 21:16
  • 1
    Also I can suggest to use copyMakeBorder function from OpenCV to add padding to an image. Commented Sep 12, 2011 at 21:21
  • oops! Sorry my apologies, I first resize the image to 12x12 and then do the padding After that I take the log of the iamge log(image+1). So sorry to mislead you. Commented Sep 12, 2011 at 21:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.