Commit 6e8940d3 authored by Théophile BORNON's avatar Théophile BORNON

Begin benchmarking

parent 3399a593
...@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 ...@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.27130.2026 VisualStudioVersion = 15.0.27130.2026
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S04_Projet", "S04_Projet\S04_Projet.csproj", "{229D3602-654B-498B-9478-5CC3982C358C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessing", "S04_Projet\ImageProcessing.csproj", "{229D3602-654B-498B-9478-5CC3982C358C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessing_Benchmark", "ImageProcessing_Benchmark\ImageProcessing_Benchmark.csproj", "{54D04E0E-009D-4928-BEF8-B2FF464536CC}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -15,6 +17,10 @@ Global ...@@ -15,6 +17,10 @@ Global
{229D3602-654B-498B-9478-5CC3982C358C}.Debug|Any CPU.Build.0 = Debug|Any CPU {229D3602-654B-498B-9478-5CC3982C358C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{229D3602-654B-498B-9478-5CC3982C358C}.Release|Any CPU.ActiveCfg = Release|Any CPU {229D3602-654B-498B-9478-5CC3982C358C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{229D3602-654B-498B-9478-5CC3982C358C}.Release|Any CPU.Build.0 = Release|Any CPU {229D3602-654B-498B-9478-5CC3982C358C}.Release|Any CPU.Build.0 = Release|Any CPU
{54D04E0E-009D-4928-BEF8-B2FF464536CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54D04E0E-009D-4928-BEF8-B2FF464536CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54D04E0E-009D-4928-BEF8-B2FF464536CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54D04E0E-009D-4928-BEF8-B2FF464536CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{54D04E0E-009D-4928-BEF8-B2FF464536CC}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ImageProcessing_Benchmark</RootNamespace>
<AssemblyName>ImageProcessing_Benchmark</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Diagnostics;
using System.IO;
namespace ImageProcessing_Benchmark
{
class Program
{
static void Main(string[] args)
{
string results = "";
Stopwatch sw = new Stopwatch();
System.Console.WriteLine("Benchmarking");
for (int i = 0; i < 100; i++)
{
sw.Restart();
Process.Start("S04_Projet.exe");
while (Process.GetProcessesByName("S04_Projet").Length != 0);
sw.Stop();
results += sw.ElapsedMilliseconds + "\n";
}
File.WriteAllText("bench.csv", results);
System.Console.WriteLine("Done");
System.Console.Read();
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("ImageProcessing_Benchmark")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("ImageProcessing_Benchmark")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("54d04e0e-009d-4928-bef8-b2ff464536cc")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading;
namespace S04_Projet namespace S04_Projet
{ {
...@@ -10,6 +10,8 @@ namespace S04_Projet ...@@ -10,6 +10,8 @@ namespace S04_Projet
{ {
private Options opt; private Options opt;
private Pixel[,] Pixels; private Pixel[,] Pixels;
private int nbProcessors;
byte[] file;
public enum grayFilterType public enum grayFilterType
{ {
...@@ -27,7 +29,7 @@ namespace S04_Projet ...@@ -27,7 +29,7 @@ namespace S04_Projet
public MyImage(string path) public MyImage(string path)
{ {
opt = new Options(); opt = new Options();
byte[] file = new byte[0]; file = new byte[0];
try try
{ {
file = File.ReadAllBytes(path); file = File.ReadAllBytes(path);
...@@ -41,14 +43,15 @@ namespace S04_Projet ...@@ -41,14 +43,15 @@ namespace S04_Projet
{ {
if (file.Length != 0) if (file.Length != 0)
{ {
FromFileToImage(file); FromFileToImage();
} }
} }
} }
public MyImage(byte[] file) public MyImage(byte[] file)
{ {
FromFileToImage(file); this.file = file;
FromFileToImage();
} }
public MyImage(Options opt, Pixel[,] Pixels) public MyImage(Options opt, Pixel[,] Pixels)
...@@ -57,7 +60,7 @@ namespace S04_Projet ...@@ -57,7 +60,7 @@ namespace S04_Projet
this.Pixels = Pixels; this.Pixels = Pixels;
} }
private void FromFileToImage(byte[] file) private void FromFileToImage()
{ {
opt = new Options(); opt = new Options();
#region Header #region Header
...@@ -85,43 +88,67 @@ namespace S04_Projet ...@@ -85,43 +88,67 @@ namespace S04_Projet
int pixelNumber = opt.width * opt.height; int pixelNumber = opt.width * opt.height;
Pixels = new Pixel[opt.width, opt.height]; Pixels = new Pixel[opt.width, opt.height];
#region Mono #region Mono
for (int i = 0; i < pixelNumber; i++) if (!Program.MULTITHREADING)
{ {
int x = i % opt.width; int x, y;
int y = i / opt.width; byte r, g, b;
byte b = file[i * 3 + opt.offset];
byte g = file[i * 3 + opt.offset + 1];
byte r = file[i * 3 + opt.offset + 2];
Pixels[x, y] = new Pixel(r, g, b);
}
#endregion
#region Parallel for (int i = 0; i < pixelNumber; i++)
/* {
Parallel.For(0, pixelNumber, i => x = i % opt.width;
{ y = i / opt.width;
Pixels[i % opt.width, i / opt.width] = new Pixel(file[i * 3 + opt.offset], b = file[i * 3 + opt.padding * y + opt.offset];
file[i * 3 + opt.offset + 1], g = file[i * 3 + opt.padding * y + opt.offset + 1];
file[i * 3 + opt.offset + 2] r = file[i * 3 + opt.padding * y + opt.offset + 2];
); Pixels[x, y] = new Pixel(r, g, b);
}); }
*/ }
#endregion #endregion
#region Multithreading #region Multithreading
int nbProcessors = Environment.ProcessorCount; if (Program.MULTITHREADING)
for (int i = 0; i < nbProcessors; i++)
{ {
nbProcessors = Environment.ProcessorCount;
int pixelPerThread = pixelNumber / nbProcessors;
Thread[] threads = new Thread[nbProcessors];
} for (int i = 0; i < nbProcessors; i++)
{
threads[i] = new Thread(new ParameterizedThreadStart(LoadImage));
threads[i].Start(i);
}
for (int i = 0; i < nbProcessors; i++) threads[i].Join();
}
#endregion #endregion
file = null;
#endregion #endregion
} }
private void LoadImage(object i)
{
int start = opt.width * opt.height / nbProcessors * (int)i;
int end = opt.width * opt.height / nbProcessors * ((int)i + 1);
int x, y;
byte r, g, b;
for (int j = start; j < end; j++)
{
x = j % opt.width;
y = j / opt.width;
b = file[j * 3 + opt.padding * y + opt.offset];
g = file[j * 3 + opt.padding * y + opt.offset + 1];
r = file[j * 3 + opt.padding * y + opt.offset + 2];
Pixels[x, y] = new Pixel(r, g, b);
}
}
private void FromImageToFile(string output) private void FromImageToFile(string output)
{ {
int nbPixel = (opt.height * opt.width); int nbPixel = (opt.height * opt.width);
...@@ -298,7 +325,7 @@ namespace S04_Projet ...@@ -298,7 +325,7 @@ namespace S04_Projet
return new MyImage(options, PixelArr); return new MyImage(options, PixelArr);
} }
public MyImage ApplyConvFilter(int[,] filter, double factor) public MyImage ApplyConvFilter(short[,] filter, double factor)
{ {
if (filter.GetLength(0) == filter.GetLength(1) && filter.GetLength(0) % 2 == 1) if (filter.GetLength(0) == filter.GetLength(1) && filter.GetLength(0) % 2 == 1)
{ {
...@@ -308,7 +335,7 @@ namespace S04_Projet ...@@ -308,7 +335,7 @@ namespace S04_Projet
Pixel[,] PixelArr = new Pixel[options.width, options.height]; Pixel[,] PixelArr = new Pixel[options.width, options.height];
int x, y; int x, y;
int[,] rMatrix, gMatrix, bMatrix; byte[,] rMatrix, gMatrix, bMatrix;
byte r, g, b; byte r, g, b;
for (int i = 0; i < nbPixel; i++) for (int i = 0; i < nbPixel; i++)
...@@ -322,7 +349,7 @@ namespace S04_Projet ...@@ -322,7 +349,7 @@ namespace S04_Projet
r = ConvolutionalResult(rMatrix, filter, size, factor); r = ConvolutionalResult(rMatrix, filter, size, factor);
g = ConvolutionalResult(gMatrix, filter, size, factor); g = ConvolutionalResult(gMatrix, filter, size, factor);
b = ConvolutionalResult(bMatrix, filter, size, factor); b = ConvolutionalResult(bMatrix, filter, size, factor);
PixelArr[x, y] = new Pixel(r, g, b); PixelArr[x, y] = new Pixel(r, g, b);
} }
...@@ -339,11 +366,11 @@ namespace S04_Projet ...@@ -339,11 +366,11 @@ namespace S04_Projet
} }
} }
private int[,] GetMatrix(int x0, int y0, int size, RGB rgb) private byte[,] GetMatrix(int x0, int y0, int size, RGB rgb)
{ {
int[,] matrix = new int[size, size]; byte[,] matrix = new byte[size, size];
for (int i = 0; i < size*size; i++) for (int i = 0; i < size * size; i++)
{ {
int x = x0 + (i % size) - ((size - 1) / 2); int x = x0 + (i % size) - ((size - 1) / 2);
int y = y0 + (i / size) - ((size - 1) / 2); int y = y0 + (i / size) - ((size - 1) / 2);
...@@ -364,13 +391,13 @@ namespace S04_Projet ...@@ -364,13 +391,13 @@ namespace S04_Projet
return matrix; return matrix;
} }
public static byte ConvolutionalResult(int[,] matrix, int[,] conv, int size, double factor) public static byte ConvolutionalResult(byte[,] matrix, short[,] conv, int size, double factor)
{ {
int r = 0;; short r = 0; ;
for (int x = 0; x < size; x++) for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++) for (int y = 0; y < size; y++)
r += matrix[x, y] * conv[x, y]; r += (short)(matrix[x, y] * conv[x, y]);
r = (int)Math.Round(r * factor); r = (short)Math.Round(r * factor);
if (r > 255) return 255; if (r > 255) return 255;
else if (r < 0) return 0; else if (r < 0) return 0;
else return (byte)r; else return (byte)r;
......
...@@ -11,58 +11,62 @@ namespace S04_Projet ...@@ -11,58 +11,62 @@ namespace S04_Projet
{ {
class Program class Program
{ {
public static bool MULTITHREADING = false;
static void Main(string[] args) static void Main(string[] args)
{ {
int[,] boxBlurFilter = new int[,] { MyImage img = new MyImage("img/lena.bmp");
img.Save("output.bmp");
/*short[,] boxBlurFilter = new short[,] {
{1,1,1 }, {1,1,1 },
{1,1,1 }, {1,1,1 },
{1,1,1 } {1,1,1 }
}; };
int[,] identityFilter = new int[,] short[,] identityFilter = new short[,]
{ {
{ 0, 0, 0 }, { 0, 0, 0 },
{ 0, 1, 0 }, { 0, 1, 0 },
{ 0, 0, 0 } { 0, 0, 0 }
}; };
int[,] edgeDetect1Filter = new int[,] short[,] edgeDetect1Filter = new short[,]
{ {
{ 1, 0, -1 }, { 1, 0, -1 },
{ 0, 0, 0 }, { 0, 0, 0 },
{ -1, 0, 1 } { -1, 0, 1 }
}; };
int[,] edgeDetect2Filter = new int[,] short[,] edgeDetect2Filter = new short[,]
{ {
{ 0, 1, 0 }, { 0, 1, 0 },
{ 1, -4, 1 }, { 1, -4, 1 },
{ 0, 1, 0 } { 0, 1, 0 }
}; };
int[,] edgeDetect3Filter = new int[,] short[,] edgeDetect3Filter = new short[,]
{ {
{ -1, -1, -1 }, { -1, -1, -1 },
{ -1, 8, -1 }, { -1, 8, -1 },
{ -1, -1, -1 } { -1, -1, -1 }
}; };
int[,] sharpenFilter = new int[,] short[,] sharpenFilter = new short[,]
{ {
{ 0, -1, 0 }, { 0, -1, 0 },
{ -1, 5, -1 }, { -1, 5, -1 },
{ 0, -1, 0 } { 0, -1, 0 }
}; };
MyImage imgg = new MyImage("img/flocon.bmp"); MyImage imgg = new MyImage("img/coco.bmp");
imgg.ApplyConvFilter(identityFilter, 1).Save("id.bmp"); imgg.ApplyConvFilter(identityFilter, 1).Save("id.bmp");
imgg.ApplyConvFilter(edgeDetect1Filter, 1).Save("edge1.bmp"); imgg.ApplyConvFilter(edgeDetect1Filter, 1).Save("edge1.bmp");
imgg.ApplyConvFilter(edgeDetect2Filter, 1).Save("edge2.bmp"); imgg.ApplyConvFilter(edgeDetect2Filter, 1).Save("edge2.bmp");
imgg.ApplyConvFilter(edgeDetect3Filter, 1).Save("edge3.bmp"); imgg.ApplyConvFilter(edgeDetect3Filter, 1).Save("edge3.bmp");
imgg.ApplyConvFilter(sharpenFilter, 1).Save("sharpen.bmp"); imgg.ApplyConvFilter(sharpenFilter, 1).Save("sharpen.bmp");
imgg.ApplyConvFilter(boxBlurFilter, (double)1/9).Save("blur.bmp"); imgg.ApplyConvFilter(boxBlurFilter, (double)1/9).Save("blur.bmp");*/
Console.ForegroundColor = ConsoleColor.White; /*Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("#############################################################"); Console.WriteLine("#############################################################");
Console.WriteLine("### Bienvenue ###"); Console.WriteLine("### Bienvenue ###");
Console.WriteLine("#############################################################"); Console.WriteLine("#############################################################");
...@@ -83,7 +87,7 @@ namespace S04_Projet ...@@ -83,7 +87,7 @@ namespace S04_Projet
//Console.Clear(); //Console.Clear();
Console.Read(); Console.Read();*/
#region Test #region Test
/*MyImage imgRotate90 = img.Rotate90(); /*MyImage imgRotate90 = img.Rotate90();
imgRotate90.Save("90.bmp"); imgRotate90.Save("90.bmp");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment