Ask Your Question

Revision history [back]

Image Convolution returns black or strange images

Hello,

I use two different methods to calculate the convolution of two images, both methods should return the same result, but they are different and both results don't seem right.

I wanted to auto correlate an image and therefore I convolve the image with a flipped version of itself. In theory it should work, but in reality, there is some bug.

Any idea why this method always returns a black image:

void AutoCorrelation1(Mat *image)
{
    cv::Mat flippedImage;

    //Flipped around the x - axis
    cv::flip(*image, flippedImage, 0);

    //Convolved both images
    cv::filter2D(*image, *image, -1, flippedImage, Point(-1,-1), 0.0, 0);
}

And this is the one with the strange results:

void AutoCorrelation2(Mat *image)
{
    cv::Mat flippedImage;

    //Flipped around the x - axis
    flip(*image, flippedImage, 0);

    //Increase depth
    flippedImage.convertTo(flippedImage, CV_64F);
    image->convertTo(*image, CV_64F);

    //DFT Both images
    DFT(image);
    DFT(&flippedImage);

    //Per element multiplication
    multiply(*image, flippedImage, *image);
    *image = *image/ 500;

    //Inverse DFT Result
    DFTInverse(image);

    //Transform Image Back
    image->convertTo(*image, CV_8U);
}

PS: DFT and DFTInverse work properly, already checked that.

Regards, VoodooCode