Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Frederic81 committed Jan 31, 2017
1 parent 3b6d1bb commit 0f106e9
Showing 16 changed files with 90 additions and 123 deletions.
Binary file modified .vs/2DDFT/v14/.suo
Binary file not shown.
19 changes: 11 additions & 8 deletions 2DDFT/2DDFT.csproj
Original file line number Diff line number Diff line change
@@ -44,22 +44,25 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DFT2D.cs" />
<Compile Include="Fourier\DFT2D.cs" />
<Compile Include="Complex.cs" />
<Compile Include="Display.cs" />
<Compile Include="Fourier\Display.cs" />
<Compile Include="Distributions.cs" />
<Compile Include="FFT.cs" />
<Compile Include="FFT2D.cs" />
<Compile Include="Filters.cs" />
<Compile Include="PhillipsParameters.cs" />
<Compile Include="Phillips.cs" />
<Compile Include="Fourier\FFT.cs" />
<Compile Include="Fourier\FFT2D.cs" />
<Compile Include="Noise\Filters.cs" />
<Compile Include="Phillips\PhillipsParameters.cs" />
<Compile Include="Phillips\Phillips.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WhiteNoise.cs" />
<Compile Include="Noise\WhiteNoise.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Filter\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
3 changes: 1 addition & 2 deletions 2DDFT/DFT2D.cs → 2DDFT/Fourier/DFT2D.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Drawing;


namespace _2DDFT
namespace _2DDFT.Fourier
{
public class DFT2D
{
60 changes: 30 additions & 30 deletions 2DDFT/Display.cs → 2DDFT/Fourier/Display.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
using System;
using System.Drawing;

namespace _2DDFT
namespace _2DDFT.Fourier
{
public class Display
public static class Display
{
public int Size { get; set; }

public Display(int size)
{
Size = size;
}

public Bitmap ReadImage(string path)
public static Bitmap ReadImage(string path)
{
return new Bitmap(Image.FromFile(path));
}

public void Picture(float[,] transform, string path)
public static void ToPicture(this float[,] transform, string path)
{
var image = new Bitmap(Size, Size);
var size = transform.GetLength(1);

var image = new Bitmap(size, size);

var max = 0.0;
for (var i = 0; i < Size; i++)
for (var i = 0; i < size; i++)
{
for (var j = 0; j < Size; j++)
for (var j = 0; j < size; j++)
{
if (max < transform[i, j])
max = transform[i, j];
}
}

for (var l = 0; l < Size; l++)
for (var l = 0; l < size; l++)
{
for (var k = 0; k < Size; k++)
for (var k = 0; k < size; k++)
{
var pixelValue = transform[l, k];
var color = Color.FromArgb((int)(pixelValue / max * 255), (int)(pixelValue / max * 255), (int)(pixelValue / max * 255));
@@ -44,15 +39,17 @@ public void Picture(float[,] transform, string path)
}

//FROM MUTIDIMENTIONAL ARRAY TO JAGGED ARRAY
public void Magnitude(Complex[,] transform, string path)
public static void Magnitude(this Complex[,] transform, string path)
{
Complex[][] floatTransform = new Complex[Size][];
var size = transform.GetLength(1);

Complex[][] floatTransform = new Complex[size][];

for (var i = 0; i < Size; i++)
for (var i = 0; i < size; i++)
{
floatTransform[i] = new Complex[Size];
floatTransform[i] = new Complex[size];

for (var j = 0; j < Size; j++)
for (var j = 0; j < size; j++)
{
floatTransform[i][j] = transform[i,j];
}
@@ -61,34 +58,36 @@ public void Magnitude(Complex[,] transform, string path)
Magnitude(floatTransform, path);
}

public void Magnitude(Complex[][] transform, string path)
public static Complex[][] Magnitude(this Complex[][] transform, string path)
{
float[,] floatTransform = new float[Size, Size];
var size = transform.Length;

float[,] floatTransform = new float[size, size];

for (var i = 0; i < Size; i++)
for (var i = 0; i < size; i++)
{
for (var j = 0; j < Size; j++)
for (var j = 0; j < size; j++)
{
floatTransform[i, j] = Complex.Modulus(transform[i][j]);
}
}

var max = 0.0;

for (var i = 0; i < Size; i++)
for (var i = 0; i < size; i++)
{
for (var j = 0; j < Size; j++)
for (var j = 0; j < size; j++)
{
if (max < floatTransform[i, j])
max = floatTransform[i, j];
}
}

var image = new Bitmap(Size, Size);
var image = new Bitmap(size, size);

for (var l = 0; l < Size; l++)
for (var l = 0; l < size; l++)
{
for (var k = 0; k < Size; k++)
for (var k = 0; k < size; k++)
{
var pixelValue = Math.Log10(1 + floatTransform[l, k]) * 255 / Math.Log10(1 + max);

@@ -101,6 +100,7 @@ public void Magnitude(Complex[][] transform, string path)
}
}
image.Save(path);
return transform;
}
}
}
4 changes: 1 addition & 3 deletions 2DDFT/FFT.cs → 2DDFT/Fourier/FFT.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;


namespace _2DDFT
namespace _2DDFT.Fourier
{
public class FFT
{
@@ -17,7 +16,6 @@ public Complex[] Inverse(Complex[] input)
for (int i = 0; i < input.Length; i++)
{
input[i] = Complex.Conjugate(input[i]);

}

var transform = Forward(input, false);
6 changes: 2 additions & 4 deletions 2DDFT/FFT2D.cs → 2DDFT/Fourier/FFT2D.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Drawing;
using System.Drawing;


namespace _2DDFT
namespace _2DDFT.Fourier
{
public class FFT2D : FFT
{
3 changes: 1 addition & 2 deletions 2DDFT/Filters.cs → 2DDFT/Noise/Filters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;


namespace _2DDFT
namespace _2DDFT.Noise
{
public class Filters
{
16 changes: 7 additions & 9 deletions 2DDFT/WhiteNoise.cs → 2DDFT/Noise/WhiteNoise.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using System.Drawing;
using System.Drawing.Imaging;

namespace _2DDFT
namespace _2DDFT.Noise
{
public class WhiteNoise : Distributions
{
public int Height { get; set; }
public int Width { get; set; }
public int Size { get; set; }

public WhiteNoise(int height, int width, int seed) : base(seed)
public WhiteNoise(int size, int seed) : base(seed)
{
Height = height;
Width = width;
Size = size;
}

public Bitmap Create(string filePath)
{
var bitmap = new Bitmap(Width, Height);
var bitmap = new Bitmap(Size, Size);

for(var i = 0; i < Width; i++)
for(var i = 0; i < Size; i++)
{
for (var j = 0; j < Height; j++)
for (var j = 0; j < Size; j++)
{
var pixelValue = Rand();

26 changes: 12 additions & 14 deletions 2DDFT/Phillips.cs → 2DDFT/Phillips/Phillips.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
using System;

namespace _2DDFT
namespace _2DDFT.Phillips
{
public class Phillips : Distributions
{
public int Width { get; set; }
public int Height { get; set; }
public int Size { get; set; }

public Phillips(int height, int width, int seed) : base(seed)
public Phillips(int size, int seed) : base(seed)
{
Height = height;
Width = width;
Size = size;
}

public Complex[][] Create()
{
var result = new float[256][];
var complexResult = new Complex[256][];
var result = new float[Size][];
var complexResult = new Complex[Size][];

float max = 0;

for (var i = 0; i < Width; i++)
for (var i = 0; i < Size; i++)
{
result[i] = new float[Width];
complexResult[i] = new Complex[Width];
result[i] = new float[Size];
complexResult[i] = new Complex[Size];

for (var j = 0; j < Height; j++)
for (var j = 0; j < Size; j++)
{
var parameter = new PhillipsParameter
{
K = new K
{
Kx = (float) (2.0 * Math.PI / Width) * (-Width/2 + i),
Ky = (float) (2.0 * Math.PI / Width) * (-Width/2 + j)
Kx = (float) (2.0 * Math.PI / Size) * (-Size/2 + i),
Ky = (float) (2.0 * Math.PI / Size) * (-Size/2 + j)
},
WindDirection = new WindDirection
{
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace _2DDFT
namespace _2DDFT.Phillips
{
public class WindDirection
{
63 changes: 24 additions & 39 deletions 2DDFT/Program.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
using System;
using System.Drawing;
using _2DDFT.Fourier;
using _2DDFT.Noise;

namespace _2DDFT
{
class Program
{
static void Main(string[] args)
static Bitmap GenerateWhiteNoise()
{
var display = new Display(256);

var fft2D = new FFT2D(256);

Console.WriteLine("--------------------2DDFT--------------------------");
var whiteNoise = new WhiteNoise(256, 256,1);
var bitmap = whiteNoise.Create("C:\\tmp\\whitenoise.jpg");

var phillips = new Phillips(256,256,1);
var phillipsSepctrum = phillips.Create();

display.Magnitude(phillipsSepctrum, "C:\\tmp\\phillips.jpg");

var transform4 = fft2D.Inverse(phillipsSepctrum);

var whiteNoise = new WhiteNoise(256, 1);
return whiteNoise.Create("C:\\tmp\\whitenoise.jpg");
}

display.Picture(transform4, "C:\\tmp\\transform4.jpg");
static Complex[][] GeneratePhillipsSpectrum()
{
var phillips = new Phillips.Phillips(256, 1);
return phillips.Create();
}

Console.WriteLine("--------------------Read Image---------------------");

static void Main(string[] args)
{
//WHITE NOISE GENERATION
var whitenoise = GenerateWhiteNoise();

var bitmap2 = display.ReadImage("C:\\tmp\\cln1.gif");
//PHILLIPS SPECTRUM FREQUENCY AND SPATIAL DOMAIN
var phillipsSpectrum = GeneratePhillipsSpectrum().Magnitude("C:\\tmp\\phillipsSpectrum.jpg");
new FFT2D(256).Inverse(phillipsSpectrum).ToPicture("C:\\tmp\\phillipsSpatialDomain.jpg");

/*Console.WriteLine("--------------------Beginning DDFT-----------------");
var transform = DFT2D.Forward(bitmap);
display.Magnitude(transform, "C:\\tmp\\transform.jpg");
Console.WriteLine("--------------------Ending DDFT--------------------");*/
//BUTTERWORTH FILTERING IN FREQUESNCY DOMAIN
var bitmap2 = Display.ReadImage("C:\\tmp\\lena.gif");

Console.WriteLine("--------------------Beginning FFT------------------");
var transform2 = new FFT2D(256).Forward(bitmap2).Magnitude("C:\\tmp\\SpectrumForwardTransform.jpg");


var transform2 = fft2D.Forward(bitmap2);
display.Magnitude(transform2, "C:\\tmp\\transform2.jpg");
Console.WriteLine("--------------------Ending FFT---------------------");
Console.WriteLine("--------------------Beging FFTInv------------------");

var result = new Filters(256).ButterWorthLowPassFilter(transform2);

display.Magnitude(result, "C:\\tmp\\filteredImage.jpg");


var transform3 = fft2D.Inverse(result);
display.Picture(transform3, "C:\\tmp\\transform3.jpg");

Console.WriteLine("--------------------Ending FFT---------------------");
result.Magnitude("C:\\tmp\\filteredImageWithButterWorth.jpg");

Console.ReadLine();
new FFT2D(256).Inverse(result).ToPicture("C:\\tmp\\Inversetransform.jpg");
}
}
}
Binary file modified 2DDFT/bin/Debug/2DDFT.exe
Binary file not shown.
Binary file modified 2DDFT/bin/Debug/2DDFT.pdb
Binary file not shown.
11 changes: 0 additions & 11 deletions 2DDFT/bin/Debug/2DDFT.vshost.exe.manifest

This file was deleted.

Binary file modified 2DDFT/obj/Debug/2DDFT.exe
Binary file not shown.
Binary file modified 2DDFT/obj/Debug/2DDFT.pdb
Binary file not shown.

0 comments on commit 0f106e9

Please sign in to comment.