FFT 标度功率谱

发布于 2024-12-18 08:27:07 字数 855 浏览 2 评论 0原文

我在使用 FFT 扩展图像的功率谱时遇到问题。代码如下

void spectrumFFT(Complex<double> *f, Complex<double> *output, int width, int height){

        Complex<double> *temp = new Complex<double>[width * height];
        Complex<double> *singleValue = new Complex<double>();            

        for(int j = 0; j < height; j++){
            for(int i = 0; i < width; i++){
                 singleValue = f[i + j * width];
                 Complex<double> tempSwap = singleValue->Mag();
                 // tempSwap assign Magnitude value from singleValue

                 temp[i + j * width] = tempSwap;                 
            }
         }

假设临时一维数组填充了大小值。我的问题是如何扩展范围在 [0 - 255) 之间的最小和最大值。

注意:输入 *f 已经是 2DFFT 的计算值,*输出值将填充幅度的最小值和最大值。

对编程有什么想法吗?

谢谢,

问候, 一郎

I have problem to scale out power spectrum of image using FFT. The code is below

void spectrumFFT(Complex<double> *f, Complex<double> *output, int width, int height){

        Complex<double> *temp = new Complex<double>[width * height];
        Complex<double> *singleValue = new Complex<double>();            

        for(int j = 0; j < height; j++){
            for(int i = 0; i < width; i++){
                 singleValue = f[i + j * width];
                 Complex<double> tempSwap = singleValue->Mag();
                 // tempSwap assign Magnitude value from singleValue

                 temp[i + j * width] = tempSwap;                 
            }
         }

Let's say temp 1-D array is fill of magnitude value. What my problem is how to scale out min and max value of magnitude which range between [0 - 255).

Note : input *f is already calculated value of 2DFFT and *output value will be filled with min and max value of magnitude.

Any idea with programming?

Thank you,

Regards,
Ichiro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好多鱼好多余 2024-12-25 08:27:07

你的问题不是 100% 清楚,所以我可能会离开,这可能不是你想要的 - 我会一般性地这样做,忽略你可能实际获得或使用的值范围。

假设您已经获得了绝对最小值和绝对最大值、vminvmax,并且您希望将整个范围缩放到 [0; 255]你可以这样做:

// move the lower end to 0
double mod_add = -vmin;
double mod_mul = 255 / (vmax + mod_add);

现在,要将一个值重新排列到我们计算的范围内:

double scaled = (value + mod_add) * mod_mul;

mod_add会将负数/值移动到正范围(其中绝对最小值将变为0)并且< code>mod_mul 将缩放整个范围(从绝对最小值到绝对最大值)以适应 [0; 255]。如果没有负值,您显然可以跳过 mod_add 。如果您想将 0 保持在中心位置(即 127),则必须跳过 mod_add 并使用 vmaxvmin< 的绝对最大值/code> 并将其缩放到 127 而不是 255。


顺便说一句,我认为您可以大大简化循环,可能会节省一些处理时间(可能无法实现,具体取决于存在的其他代码):

const unsigned int num = width * height;
for (unsigned int i = 0; i < num; i++)
    temp[i] = f[i]->Mag();

另外,正如所提到的奥利在注释,您不应该在开始时向 singleValue 分配任何值,因为无论如何它都会在稍后被覆盖。

Your question isn't 100% clear, so I might be off and this might be not what you're looking for - I'll do it in general, ignoring the value range you might actually get or use.

Assuming you've got the absolute minimum and the absolute maximum value, vmin and vmax and you'd like to scale the whole range to [0; 255] you can do this that way:

// move the lower end to 0
double mod_add = -vmin;
double mod_mul = 255 / (vmax + mod_add);

Now, to rearrange one value to the range we calculated:

double scaled = (value + mod_add) * mod_mul;

mod_add will move negative numbers/values to the positive range (where the absolute minimum will become 0) and mod_mul will scale the whole range (from absolute minimum to absolute maximum) to fit into [0; 255]. Without negative values you're able to skip mod_add obviously. If you'd like to keep 0 in center (i.e. at 127) you'll have to skip mod_add and instead use the absolute maximum of vmax and vmin and scale that to 127 instead of 255.


On a side note, I think you could simplify your loop a lot, possibly saving some processing time (might not be possible depending on other code being there):

const unsigned int num = width * height;
for (unsigned int i = 0; i < num; i++)
    temp[i] = f[i]->Mag();

Also, as mentioned by Oli in the comments, you shouldn't assign any value to singleValue in the beginning, as it's overwritten later on anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文