image - 如何使用FFT根据局部方向和密度调整具有不同gabor滤波器的图像?

标签 image filter fft fingerprint wavelet

我目前正在开发一个使用 生成合成指纹的库。 SFinGe 方法(由 Maltoni、Maio 和 Cappelli 提供)链接:http://biolab.csr.unibo.it/research.asp?organize=Activities&select=&selObj=12&pathSubj=111%7C%7C12&
其中一个步骤要求我将不同的 gabor 过滤器应用于图像,图像中的每个像素都有一个相关的方向和频率,因此卷积不是在整个图像上使用一个内核完成的,但过滤器必须在此过程中根据情况而改变在像素的这些属性上,图像上的每个像素都以不同的方式改变。
如果您以这种方式应用过滤器,并对图像进行多次卷积(您还必须在每次卷积后对图像进行二值化),您将获得:
enter image description here
一个主指纹,这个图像需要大约 20 秒才能生成(这太慢了,这就是我想用 FFT 来做的原因),因为我必须执行 5 次卷积才能完成它(你从几个开始随机黑点)。
我的过滤器是 30x30,图像是 275x400。总共有 36000 个过滤器,每个度数和密度(密度从 0 到 100)一个。我计划将过滤器的数量从 36000 减少到 9000,因为我可以用它们覆盖所有角度。此外,所有滤波器都经过预先计算并存储在滤波器组中。
这是gabor卷积实现的C#源代码:
这两种方法执行卷积:

    /// <summary>
    /// Convolve the image with the different filters depending on the orientation and density of the pixel.
    /// </summary>
    /// <param name="image">The image to be filtered.</param>
    /// <param name="directionalMap">The directional map.</param>
    /// <param name="densityMap">The density map.</param>
    /// <returns></returns>
    public double[,] Filter(double[,] image, double[,] directionalMap, double[,] densityMap)
    {
        int       midX                          = FILTER_SIZE / 2;
        int       midY                          = FILTER_SIZE / 2;
        double[,] filteredImage                 = new double[image.GetLength(0), image.GetLength(1)];
        double[,] filteredImageWithValuesScaled = new double[image.GetLength(0), image.GetLength(1)];
        double[,] finalImage                    = new double[image.GetLength(0), image.GetLength(1)];

        for (int i = 0; i < image.GetLength(0); i++)
            for (int j = 0; j < image.GetLength(1); j++)
            {

                double pixelValue = GetPixelConvolutionValue(image, this.filterBank[(int)Math.Floor((directionalMap[i, j] * 180 / Math.PI))][Math.Round(densityMap[i, j], 2)], i - midX, j - midY);

                filteredImage[i, j] = pixelValue;
            }

        filteredImageWithValuesScaled = this.RescaleValues(filteredImage, 0.0, 255.0);

        return filteredImageWithValuesScaled;
    }
    /// <summary>
    /// Gets the pixel convolution value.
    /// </summary>
    /// <param name="image">The image.</param>
    /// <param name="filter">The filter.</param>
    /// <param name="sourceX">The source X.</param>
    /// <param name="sourceY">The source Y.</param>
    /// <returns></returns>
    private double GetPixelConvolutionValue(double[,] image, double[,] filter, int sourceX, int sourceY)
    {
        double result      = 0.0;
        int    totalPixels = 0;

        for (int i = 0; i < filter.GetLength(0); i++)
        {
            if(i + sourceX < 0 || i + sourceX >= image.GetLength(0))
                continue;

            for (int j = 0; j < filter.GetLength(1); j++)
            {
                if(j + sourceY < 0 || j + sourceY >= image.GetLength(1))
                    continue;

                double deltaResult = image[sourceX + i,sourceY + j] * filter[i, j];
                result += deltaResult;

                ++totalPixels;
            }
        }

        double filteredValue = result / totalPixels;
        return filteredValue;
    }
这两种方法为滤波器组生成不同的 Gabor 滤波器:
    /// <summary>
    /// Creates the gabor filter.
    /// </summary>
    /// <param name="size">The size.</param>
    /// <param name="angle">The angle.</param>
    /// <param name="wavelength">The wavelength.</param>
    /// <param name="sigma">The sigma.</param>
    /// <returns></returns>
    public double[,] CreateGaborFilter(int size, double angle, double wavelength, double sigma)
    {
        double[,] filter    = new double[size, size];
        double    frequency = 7 + (100 - (wavelength * 100)) * 0.03;

        int windowSize = FILTER_SIZE/2;

        for (int y = 0; y < size; ++y)
        {
            for (int x = 0; x < size; ++x)
            {
                int dy = -windowSize + y;
                int dx = -windowSize + x;

                filter[x, y] = GaborFilterValue(dy, dx, frequency, angle, 0, sigma, 0.80);
            }
        }

        return filter;
    }
    /// <summary>
    /// Gabor filter values generation.
    /// </summary>
    /// <param name="x">The x.</param>
    /// <param name="y">The y.</param>
    /// <param name="lambda">The wavelength.</param>
    /// <param name="theta">The orientation.</param>
    /// <param name="phi">The phaseoffset.</param>
    /// <param name="sigma">The gaussvar.</param>
    /// <param name="gamma">The aspectratio.</param>
    /// <returns></returns>
    double GaborFilterValue(int x, int y, double lambda, double theta, double phi, double sigma, double gamma)
    {
        double xx = x * Math.Cos(theta) + y * Math.Sin(theta);
        double yy = -x * Math.Sin(theta) + y * Math.Cos(theta);

        double envelopeVal = Math.Exp(-((xx * xx + gamma * gamma * yy * yy) / (2.0f * sigma * sigma)));

        double carrierVal = Math.Cos(2.0f * (float)Math.PI * xx / lambda + phi);

        double g = envelopeVal * carrierVal;

        return g;
    }
我的目标是将这个时间减少到 1 秒以下(有几个程序在这段时间内做完全相同的事情)。因此,由于直接卷积方法对我不起作用,我决定实现快速傅立叶变换卷积,但问题在于 FFT 一次将相同的内核应用于整个图像,我需要更改每个像素的内核,因为每个像素都必须根据其属性(密度和方向)进行更改。在这篇文章中 How to apply Gabor wavelets to an image? reve-etrange 解释了如何将不同的 gabor 过滤器应用于图像,但问题是他这样做的方式是将不同的过滤器应用于整个图像,然后对响应求和,而我需要的是从不同像素到不同像素的响应过滤器。
这是当我将一个过滤器与图像进行卷积(使用 FFT)时发生的情况:
enter image description here
这是使用的过滤器:
enter image description here
这是它卷积的图像:
enter image description here
这是 FFT 实现的 C# 算法:
    /// <summary>
    /// Convolve the image using FFT.
    /// </summary>
    /// <param name="image">The image to be filtered.</param>
    /// <param name="directionalMap">The directional map.</param>
    /// <param name="densityMap">The density map.</param>
    /// <param name="FFT">if set to <c>true</c> [FFT].</param>
    /// <returns></returns>
    public double[,] Filter(double[,] image, double[,] directionalMap, double[,] densityMap, bool FFT)
    {
        double[,] filter        = null;
        double[,] paddedFilter  = null;
        double[,] paddedImage   = null;
        double[,] croppedImage  = null;
        double[,] filteredImage = new double[image.GetLength(0), image.GetLength(1)];
        double[,] filteredImageWithValuesScaled = new double[image.GetLength(0), image.GetLength(1)];
        double[,] finalImage = new double[image.GetLength(0), image.GetLength(1)];

        filter = this.filterBank[70][0];
        paddedFilter = PadImage(filter, 512, 512, 0, 0); // Pad the filter to have a potency of 2 dimensions.
        paddedImage = PadImage(image, 512, 512, 0, 0);   // Pad the image to have a potency of 2 dimensions.

        FFT fftOne = new FFT(paddedImage);
        FFT fftTwo = new FFT(paddedFilter);

        fftOne.ForwardFFT();
        fftTwo.ForwardFFT();

        FFT result = fftOne * fftTwo;

        result.InverseFFT();

        filteredImage = result.GreyImage;

        filteredImageWithValuesScaled = this.RescaleValues(filteredImage, 0.0, 255.0);

        croppedImage = CropImage(filteredImageWithValuesScaled, image.GetLength(0), image.GetLength(1));

        return croppedImage;
    }
所以我要问的是,您如何使用 FFT 获得从不同像素到不同内核的响应?如果这是不可能的,有没有办法改进我的直接卷积,使其至少快 20 倍?
是否可以使用所有过滤器制作一个内核,以便我可以将它们应用于整个图像?

最佳答案

我找到了一种方法,可以使用不同的 gabor 滤波器对图像进行卷积,并使用 FFT 根据像素的局部特征收集像素的响应。

这称为上下文过滤,通常当您过滤图像时,您只会将单个内核应用于整个事物,但在上下文过滤中,过滤器的特征会根据本地上下文(在这种情况下,像素的密度和方向)而变化。

在直接卷积中,过程非常简单,您只需在卷积的每一步更改内核,但在 FFT 卷积中,由于内核应用于频域中的图像,您无法在此过程中更改滤波器属性。因此,您这样做的方法是分别将图像与每个过滤器进行卷积,这将提供 N 个过滤图像,其中 N 是过滤器组中过滤器的数量,然后您必须构建最终图像,从中获取信息基于您正在重新创建的像素的上下文的不同过滤图像。

因此,对于每个像素,您查看其方向和密度属性,然后从过滤图像中获取该像素位置的值,该图像是通过将原始图像与具有相同属性的过滤器进行卷积而生成的。
以下是该过程的示例:

这是方向图的图形表示。

enter image description here

我对所有像素使用相同的密度来减少生成的过滤器数量。

这是源图像:

enter image description here

这是使用的三个过滤器的示例(0 度、45 度、90 度):

enter image description here enter image description here enter image description here

以下是源图像与不同过滤器进行不同程度卷积的三个示例:

enter image description here

enter image description here

enter image description here

最后这是生成的图像,图像是根据像素的方向和密度从不同过滤图像中获取像素值创建的。

enter image description here

这个过程是很多 比直接卷积慢 =(,因为你必须先用所有的过滤器对原始图像进行卷积。生成最终图像大约需要一分钟。
到目前为止,我似乎坚持使用直接卷积=/。

谢谢阅读。

关于image - 如何使用FFT根据局部方向和密度调整具有不同gabor滤波器的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12878754/

相关文章:

javascript - 带有组合框的 ExtJS 过滤器错误

linux - 在邮件中嵌入图像并使用 Linux 邮件将其发送到 Outlook 2007

Python - 如何运行 .py 文件?

filter - 用于多个参数的 angular2 管道

javascript - Angularjs 自定义过滤器不触发

c - 在哪里可以找到 radix-5 FFT 实现?

Opencl FFT 库?有什么新的或不为人所知的吗?

numpy - 在NumPy中使用FFT时的频率单位

html img 百分比在 ipad 中看起来很尴尬

html - 如何用css斜划线