user366312
user366312

Reputation: 16908

Why is AForge.net giving a different output in case of FFT Auto-correlation?

See this related question.

I want to obtain the same outcome using AForge.net framework. The output should match the following:

enter image description here

The output seems to be not coming as expected:

Why is the output different in AForge.net?

.

Source Code

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        Bitmap image = (Bitmap)Bitmap.FromFile(@"StandardImage\\lena.png");
        Bitmap conv = new Bitmap(image.Width, image.Height, image.PixelFormat);

        ComplexImage cImage = ComplexImage.FromBitmap(image);
        cImage.ForwardFourierTransform();

        ComplexImage cKernel = ComplexImage.FromBitmap(image);
        cImage.ForwardFourierTransform();

        ComplexImage convOut = ComplexImage.FromBitmap(conv);
        convOut.ForwardFourierTransform();

        for (int y = 0; y < cImage.Height; y++)
        {
            for (int x = 0; x < cImage.Width; x++)
            {
                convOut.Data[x, y] = cImage.Data[x, y] * cKernel.Data[x, y];
            }
        }

        convOut.BackwardFourierTransform();

        Bitmap bbbb = convOut.ToBitmap();

        pictureBox1.Image = bbbb;

    }
}

Upvotes: 1

Views: 350

Answers (2)

Amir Ehsani
Amir Ehsani

Reputation: 136

The main problem is

    ComplexImage cKernel = ComplexImage.FromBitmap(image);
    //cImage.ForwardFourierTransform(); //<--- This line should be FFT of cKernel
    cKernel.ForwardFourierTransform();

This would solve the problem you mentioned in the resulting image, but if you want to get an image similar to the bottom right image you need to do some normalization to increase the intensity of pixels.


update: The bottom right image is actually a Fourier image so I think we should remove the BFF.

//convOut.BackwardFourierTransform();

Upvotes: 2

Guy haimovitz
Guy haimovitz

Reputation: 1625

It is seems like you are not using a gaussian kernel with Aforge, Anyway, the library has a method for convolution with gaussian:

int w=4,h=11;
GaussianBlur filter = new GaussianBlur( w, h );
// apply the filter
filter.ApplyInPlace( image );

Try it and the output should be the same as the others.

Upvotes: 0

Related Questions