FFT应用图像的带通滤波器。(如ImageJ带通滤波算法)

时间:2022-03-31 08:19:05

There is a good function that I need, which is implemented in the Java program: ImageJ. I need to understand the algorithm used there. The function has several parameters: link text

我需要一个很好的函数,它在Java程序中实现:ImageJ。我需要理解这里使用的算法。该函数有几个参数:链接文本

And before using FFT it converts image to a special one: The Bandpass Filter uses a special algorithm to reduce edge artifacts (before the Fourier transform, the image is extended in size by attaching mirrored copies of image parts outside the original image, thus no jumps occur at the edges)

在使用FFT之前,它将图像转换为一个特殊的图像:带通滤波器使用一种特殊的算法来减少边缘伪影(在进行傅里叶变换之前,通过在原始图像外部附加镜像图像部件来扩展图像的大小,因此边缘不会发生跳转)

Can you tell me more about this special transform? Actually tiling mirrored image.

你能告诉我更多关于这个特殊变换的信息吗?实际上花砖镜像图像。

I am writing on C++ and wish to rewrite that part of the program on C++.

我正在写c++,并希望重写c++程序的这一部分。

EDIT1: I need to understand how it does that tiling mirrored image operation, may be it is special one. Actually at first it converts image to a new sized image, so for my images it will be: convertion from 600X480 to 1024X1024 sized image. How the tiling is used here?

我需要了解它是如何做的瓦片镜像操作,也许它是特别的一个。实际上,它首先将图像转换为一个新的大小图像,因此对于我的图像,它将是:从600X480转换为1024X1024大小的图像。瓷砖在这里是如何使用的?

EDIT2: Also it is hard to understand this description of tileMirrored function:

而且很难理解tilemirrated函数的描述:

Puts ImageProcessor (ROI) into a new ImageProcessor of size width x height y at position (x,y). The image is mirrored around its edges to avoid wrap around effects of the FFT. What is meant by "...of size width x height y at position (x,y). "?

将ImageProcessor (ROI)放到一个新的图像处理器中,该处理器的宽度为x高度为y (x,y)。图像被镜像在其边缘,以避免围绕FFT的影响。“…”是什么意思?尺寸宽度x高度y在位置(x,y)。”?

EDIT3: I implemented that bandpass filter, and it gives the same results as the original program. But, the algorithm itself in original program (also in my program) is very slow I want to use that filter not once in my program, but it calculates approximately 0.5 to 2 seconds each call (depending on parameter value). There is used an FHT transform (not FFT), is it more quickly than FFT? I think the filter itself is not optimized, please see filterLargeSmall function implementation: source code

EDIT3:我实现了带通滤波器,它的结果与原始程序相同。但是,原始程序中的算法本身(也在我的程序中)非常慢,我不想在程序中使用这个过滤器,但是它会计算每次调用大约0.5到2秒(取决于参数值)。有一个FHT转换(不是FFT),它比FFT快吗?我认为过滤器本身没有优化,请见filterLargeSmall函数实现:源代码

1 个解决方案

#1


1  

I don't know exactly how that function works, but here's the basic algorithm for a similar function:

我不知道这个函数是如何工作的,但是这是一个类似函数的基本算法:

  1. Determine the smallest power of two (call it newSize) that is larger than the larger of the two dimensions of the image (call them xSize & ySize).

    确定两个(称为newSize)的最小值(称为newSize),它大于图像的两个维度(称为xSize和ySize)。

  2. Create a new square image of size newSize by newSize and copy the contents of the image to the center of the new image (ie. the top-left of the image should start at (newSize / 2 - xSize / 2, newSize / 2 - ySize / 2)).

    按新大小创建一个新的大小为新大小的方形图像,并将图像内容复制到新图像的中心。图像的左上角应该从(newSize / 2 - xSize / 2, newSize / 2 - ySize / 2)开始。

  3. Fill in the remaining pixels as follows, for each pixel at (x, y):

    对(x, y)处的每一个像素,填写剩余像素如下:

    • if x < (newSize / 2 - xSize / 2), copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x and row y.
    • 如果x < (newSize / 2 - xSize / 2),复制列上的像素(newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x和行y。
    • if y < (newSize / 2 - ySize / 2), copy the pixel at row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y and column x.
    • 如果y < (newSize / 2 - ySize / 2),复制行上的像素(newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y和列x。
    • if both of the above are true, copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x, row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y.
    • 如果上述两种方法都是正确的,则将像素复制到列(newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x、行(newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y。
    • if x > (newSize / 2 + xSize / 2), copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row y.
    • 如果x > (newSize / 2 + xSize / 2),复制列上的像素(newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x和行y。
    • if y > (newSize / 2 + ySize / 2), copy the pixel at row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y and column x.
    • 如果y > (newSize / 2 + ySize / 2),复制行上的像素(newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y和列x。
    • if both of the above are true, copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y.
    • 如果上述两种方法都成立,则复制列上的像素(newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x和行(newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y。

There are probably libraries that will make this easier (ie. flipping and copying image data), but I am not familiar with C++, and this should be pretty easy to code yourself as long as performance isn't a huge issue. Be careful of rounding issues for images with odd dimensions: make sure they're consistent.

可能有一些库会使这变得更容易。但是我不熟悉c++,而且只要性能不是一个大问题,就很容易编写代码。对于具有奇数维的图像,要注意四舍五入问题:确保它们是一致的。

#1


1  

I don't know exactly how that function works, but here's the basic algorithm for a similar function:

我不知道这个函数是如何工作的,但是这是一个类似函数的基本算法:

  1. Determine the smallest power of two (call it newSize) that is larger than the larger of the two dimensions of the image (call them xSize & ySize).

    确定两个(称为newSize)的最小值(称为newSize),它大于图像的两个维度(称为xSize和ySize)。

  2. Create a new square image of size newSize by newSize and copy the contents of the image to the center of the new image (ie. the top-left of the image should start at (newSize / 2 - xSize / 2, newSize / 2 - ySize / 2)).

    按新大小创建一个新的大小为新大小的方形图像,并将图像内容复制到新图像的中心。图像的左上角应该从(newSize / 2 - xSize / 2, newSize / 2 - ySize / 2)开始。

  3. Fill in the remaining pixels as follows, for each pixel at (x, y):

    对(x, y)处的每一个像素,填写剩余像素如下:

    • if x < (newSize / 2 - xSize / 2), copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x and row y.
    • 如果x < (newSize / 2 - xSize / 2),复制列上的像素(newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x和行y。
    • if y < (newSize / 2 - ySize / 2), copy the pixel at row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y and column x.
    • 如果y < (newSize / 2 - ySize / 2),复制行上的像素(newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y和列x。
    • if both of the above are true, copy the pixel at column (newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x, row (newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y.
    • 如果上述两种方法都是正确的,则将像素复制到列(newSize / 2 - xSize / 2) + (newSize / 2 - xSize / 2) - x、行(newSize / 2 - ySize / 2) + (newSize / 2 - ySize / 2) - y。
    • if x > (newSize / 2 + xSize / 2), copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row y.
    • 如果x > (newSize / 2 + xSize / 2),复制列上的像素(newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x和行y。
    • if y > (newSize / 2 + ySize / 2), copy the pixel at row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y and column x.
    • 如果y > (newSize / 2 + ySize / 2),复制行上的像素(newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y和列x。
    • if both of the above are true, copy the pixel at column (newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x and row (newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y.
    • 如果上述两种方法都成立,则复制列上的像素(newSize / 2 + xSize / 2) + (newSize / 2 + xSize / 2) - x和行(newSize / 2 + ySize / 2) + (newSize / 2 + ySize / 2) - y。

There are probably libraries that will make this easier (ie. flipping and copying image data), but I am not familiar with C++, and this should be pretty easy to code yourself as long as performance isn't a huge issue. Be careful of rounding issues for images with odd dimensions: make sure they're consistent.

可能有一些库会使这变得更容易。但是我不熟悉c++,而且只要性能不是一个大问题,就很容易编写代码。对于具有奇数维的图像,要注意四舍五入问题:确保它们是一致的。