FFT 标度功率谱
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题不是 100% 清楚,所以我可能会离开,这可能不是你想要的 - 我会一般性地这样做,忽略你可能实际获得或使用的值范围。
假设您已经获得了绝对最小值和绝对最大值、
vmin
和vmax
,并且您希望将整个范围缩放到 [0; 255]你可以这样做:现在,要将一个值重新排列到我们计算的范围内:
mod_add
会将负数/值移动到正范围(其中绝对最小值将变为0)并且< code>mod_mul 将缩放整个范围(从绝对最小值到绝对最大值)以适应 [0; 255]。如果没有负值,您显然可以跳过mod_add
。如果您想将 0 保持在中心位置(即 127),则必须跳过mod_add
并使用vmax
和vmin< 的绝对最大值/code> 并将其缩放到 127 而不是 255。
顺便说一句,我认为您可以大大简化循环,可能会节省一些处理时间(可能无法实现,具体取决于存在的其他代码):
另外,正如所提到的奥利在注释,您不应该在开始时向
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
andvmax
and you'd like to scale the whole range to [0; 255] you can do this that way:Now, to rearrange one value to the range we calculated:
mod_add
will move negative numbers/values to the positive range (where the absolute minimum will become 0) andmod_mul
will scale the whole range (from absolute minimum to absolute maximum) to fit into [0; 255]. Without negative values you're able to skipmod_add
obviously. If you'd like to keep 0 in center (i.e. at 127) you'll have to skipmod_add
and instead use the absolute maximum ofvmax
andvmin
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):
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.