最糟糕的是人们在生活中经常受到错误志向的阻碍而不自知,真到摆脱了那些阻碍时才能明白过来。 —— 歌德
页面代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<pre class="csharp" name="code">
<%-- // 二维傅立叶变换 --%>
public static Bitmap Fourier(Bitmap tp)
{
// 原图像的宽与高
int w = tp.Width;
int h = tp.Height;
// 傅立叶变换的实际宽高
long lw = 1;
long lh = 1;
// 迭代次数
int wp = 0; int hp = 0;
long i, j;
long n,m;
double temp;
byte [] ky = new byte[w*h];
ky = ChangeByte(tp);
COMPLEX[] t; COMPLEX[] f;
while (lw * 2 <= w)
{
lw *= 2;
wp++;
}
while (lh * 2 <= h)
{
lh *= 2;
hp++;
}
t = new COMPLEX[lw * lh];
f = new COMPLEX[lw * lh];
COMPLEX[] tw = new COMPLEX[lw];
COMPLEX[] th = new COMPLEX[lw];
for (i = 0; i < lh; i++)
{
for (j = 0; j < lw; j++)
{
t[i*lw + j].re = ky[ i*w+ j];
t[i *lw + j].im = 0;
}
}
for (i = 0; i < lh; i++) // 垂直方向傅立叶变换
{
Array.Copy(t, i * lw, tw, 0, lw);
Array.Copy(f, i * lw, th, 0, lw);
FFT(tw, th, wp);
// Array.Copy(tw, 0, t, i * lw, lw);
Array.Copy(th, 0, f, i * lw, lw);
}
for (i = 0; i < lh; i++)
{
for (j = 0; j < lw; j++)
{
t[j * lh + i].re = f[i * lw + j].re;
t[j * lh + i].im = f[i * lw + j].im;
}
}
COMPLEX[] ow = new COMPLEX[lh];
COMPLEX[] oh = new COMPLEX[lh];
for (i = 0; i < lw; i++)
{
Array.Copy(t, i * lh, ow, 0, lh);
Array.Copy(f, i * lh, oh, 0, lh);
FFT(ow, oh, hp);
//Array.Copy(ow, 0, t, i * lh, lh);
oh.CopyTo(f, i * lh);
}
for (i = 0; i < lh; i++)
{
for (j = 0; j < lw; j++)
{
temp = Math.Sqrt(f[j * lh + i].re * f[j * lh + i].re + f[j * lh + i].im * f[j * lh + i].im) / 100;
if (temp > 255)
{
temp = 255;
}
n = i < lh / 2 ? i + lh / 2 : i - lh / 2;
m = j < lw / 2 ? j + lw / 2 : j - lw / 2;
ky[n* w + m] = (byte)(temp);
}
}
tp = ChangeBitmap(ky, tp);
return tp;
}</pre>
<p>
<br />
</p>
<pre></pre>
<p>
测试图片:
</p>
<p>
</p>
<table border="1" cellspacing="1" cellpadding="1" width="200">
<tbody>
<tr>
<td>
原图
</td>
<td>
傅立叶变换图
</td>
</tr>
<tr>
<td>
<img src="https://img-my.csdn.net/uploads/201204/14/1334405526_4469.jpg" alt="">
</td>
<td>
<img alt="" src="https://img-my.csdn.net/uploads/201204/14/1334405154_9532.jpg">
</td>
</tr>
<tr>
<td>
<img alt="" src="https://img-my.csdn.net/uploads/201204/14/1334404863_5617.jpg" width="260"
height="256">
</td>
<td>
<img alt="" src="https://img-my.csdn.net/uploads/201204/14/1334404854_1591.jpg">
</td>
</tr>
</tbody>
</table>
ok了。<p>
</p>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
</body>
</html>
运行结果如图:
![这里写图片描述](https://img-blog.csdn.net/20160930234936126)