二维傅立叶变换

最糟糕的是人们在生活中经常受到错误志向的阻碍而不自知,真到摆脱了那些阻碍时才能明白过来。 —— 歌德


页面代码:

<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>

运行结果如图:

这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值