Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换
2021-02-09 12:17
阅读:776
??
[函数名称]
1,一维FFT变换函数?????????Complex[]?FFT(Complex[]?sourceData,?int?countN)
??2,二维FFT变换函数???????????Complex[]?FFT2(byte[]?imageData,bool?inv)
??3,图像傅立叶变换幅度函数?????WriteableBitmap?FFTImage()
??4,图像傅立叶变换相位函数?????WriteableBitmap?FFTPhaseImage()
[算法说明]
??关于傅立叶变换这一小节,由于算法较为复杂,因此在后面专门介绍,这里略去。
[函数代码]
??代码包括两个类库:1,复数运算类Complex.cs???2,FFT变换类DFT.cs
1.Complex.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Win8ImageProcess
{
class Complex
{
//复数实部
private double real = 0.0;
//复数虚部
private double imaginary = 0.0;
public double Real
{
get
{
return real;
}
set
{
real = value;
}
}
public double Imaginary
{
get
{
return imaginary;
}
set
{
imaginary = value;
}
}
public Complex()
{
}
public Complex(double dbreal, double dbimag)
{
real = dbreal;
imaginary = dbimag;
}
public Complex(Complex other)
{
real = other.real;
imaginary = other.imaginary;
}
//复数加运算
public static Complex operator +(Complex comp1, Complex comp2)
{
return comp1.Add(comp2);
}
//复数减运算
public static Complex operator -(Complex comp1, Complex comp2)
{
return comp1.Subtract(comp2);
}
//复数乘运算
public static Complex operator *(Complex comp1, Complex comp2)
{
return comp1.Multiply(comp2);
}
public Complex Add(Complex comp)
{
double x = real + comp.real;
double y = imaginary + comp.imaginary;
return new Complex(x, y);
}
public Complex Subtract(Complex comp)
{
double x = real - comp.real;
double y = imaginary - comp.imaginary;
return new Complex(x, y);
}
public Complex Multiply(Complex comp)
{
double x = real * comp.real - imaginary * comp.imaginary;
double y = real * comp.imaginary + imaginary * comp.real;
return new Complex(x, y);
}
//幅值
public double Abs()
{
double x = Math.Abs(real);
double y = Math.Abs(imaginary);
if (real == 0)
{
return y;
}
if (imaginary == 0)
{
return x;
}
if (x > y)
{
return (x * Math.Sqrt(1 + (y / x) * (y / x)));
}
else
{
return (y * Math.Sqrt(1 + (x / y) * (x / y)));
}
}
//相位角
public double Angle()
{
if (real == 0 && imaginary == 0)
return 0;
if (real == 0)
{
if (imaginary > 0)
return Math.PI / 2;
else
return -Math.PI / 2;
}
else
{
if (real > 0)
return Math.Atan2(imaginary, real);
else
{
if (imaginary >= 0)
return Math.Atan2(imaginary, real) + Math.PI;
else
return Math.Atan2(imaginary, real) - Math.PI;
}
}
}
//共轭
public Complex Conjugate()
{
return new Complex(this.real, -this.imaginary);
}
}
}
2.DFT.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Windows.UI.Xaml.Media.Imaging;
using System.Runtime.InteropServices.WindowsRuntime;
namespace Win8ImageProcess
{
public sealed class DFTClass
{
private static WriteableBitmap srcImage;
private static byte[] imageData;
private static int w = 0;
private static int h = 0;
public DFTClass(WriteableBitmap image)
{
srcImage = image;
w = image.PixelWidth;
h = image.PixelHeight;
}
//一维FFT变换
private Complex[] FFT(Complex[] sourceData, int countN)
{
//求fft的级数
int r = Convert.ToInt32(Math.Log(countN, 2));
//定义加权系数W
Complex[] w = new Complex[countN / 2];
Complex[] interVar1 = new Complex[countN];
Complex[] interVar2 = new Complex[countN];
interVar1 = (Complex[])sourceData.Clone();
//求取加权系数W
double angle = 0;
for (int i = 0; i >= 1;
}
interVar2[rev] = interVar1[j];
}
return interVar2;
}
//二维fft变换
private Complex[] FFT2(byte[] imageData,bool inv)
{
int bytes = w * h;
byte[] bmpValues = new byte[bytes];
Complex[] tempCom1 = new Complex[bytes];
bmpValues = (byte[])imageData.Clone();
for (int i = 0; i
/// 图像FFT幅度图函数
///
///
public WriteableBitmap FFTImage()
{
WriteableBitmap grayImage = new WriteableBitmap(w, h);
byte[] temp = srcImage.PixelBuffer.ToArray();
imageData = new byte[w * h];
byte tempByte = 0;
for (int j = 0; j tempArray[i])
{
a = tempArray[i];
}
if (b
/// 图像FFT相位图函数
///
///
public WriteableBitmap FFTPhaseImage()
{
WriteableBitmap grayImage = new WriteableBitmap(w, h);
byte[] temp = srcImage.PixelBuffer.ToArray();
imageData = new byte[w * h];
byte tempByte = 0;
for (int j = 0; j tempArray[i])
{
a = tempArray[i];
}
if (b 
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换
文章链接:http://soscw.com/index.php/essay/53090.html
文章标题:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换
文章链接:http://soscw.com/index.php/essay/53090.html
评论
亲,登录后才可以留言!