Ask Your Question
0

Image Convolution returns black or strange images

asked 2013-02-06 04:55:47 -0600

VoodooCode gravatar image

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-02-09 11:36:59 -0600

updated 2013-02-09 11:40:50 -0600

You can use template matching for the convolution.This topic will help you.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-06 04:55:47 -0600

Seen: 535 times

Last updated: Feb 09 '13