Commit 1825f502 authored by BORNON Théophile's avatar BORNON Théophile

Filter command line

parent fb9a6f07
......@@ -26,6 +26,7 @@ namespace S04_Projet
Histogram,
Dithering,
Debug,
Multithreading,
Save
}
......@@ -40,10 +41,10 @@ namespace S04_Projet
"Passage à une image en nuances de gris (luminosité)",
"Superposer avec une autre image",
"Ajouter un filtre de convolution",
//"Créer une image",
"Générer les histogrammes de l'image",
"Floyd-Steinberg dithering",
"Activer le mode debug",
"Activer le multithreading",
"Sauvegarder"
};
......@@ -52,6 +53,7 @@ namespace S04_Projet
public static string fileInfos;
private static Stopwatch sw = new Stopwatch();
private static Menu mainMenu = new Menu(menuItems);
private static Menu filterMenu = new Menu(Filter.Noms);
/// <summary>
/// Charge l'image
......@@ -155,6 +157,9 @@ namespace S04_Projet
case Operation.Debug:
output = DebugOperation(img);
break;
case Operation.Multithreading:
output = MultithreadingOperation(img);
break;
case Operation.Save:
SaveOperation(img);
break;
......@@ -255,8 +260,15 @@ namespace S04_Projet
public static MyImage FilterOperation(MyImage img)
{
int choix;
MyImage newImage;
Console.Clear();
Console.WriteLine("Quel filtre souhaitez-vous appliquer ?");
choix = filterMenu.ShowMenu(0,3);
sw.Restart();
newImage = img.Filter(Filter.Filtres[choix], Filter.Facteurs[choix]);
return null;
return newImage;
}
public static MyImage HistogramOperation(MyImage img)
......@@ -305,6 +317,21 @@ namespace S04_Projet
return img;
}
public static MyImage MultithreadingOperation(MyImage img)
{
if(Program.MULTITHREADING)
{
Program.MULTITHREADING = false;
menuItems[(int)Operation.Multithreading] = "Activer le multithreading";
}
else
{
Program.MULTITHREADING = true;
menuItems[(int)Operation.Multithreading] = "Désactiver le multithreading";
}
return img;
}
public static MyImage SaveOperation(MyImage img)
{
string path = "";
......
......@@ -8,59 +8,51 @@ namespace S04_Projet
{
public class Filter
{
public static short[,] boxBlurFilter = new short[,]
public static string[] Noms = new string[] {
"Augmenter le contraste",
"Flou",
"Renforcement des bords",
"Détection des bords",
"Repoussage"
};
public static double[] Facteurs = new double[] { 1, 1 / 9.0, 1, 1, 1 };
private static short[,] contrastPlus = new short[,]
{
{ 0,-1, 0 },
{-1, 5,-1 },
{ 0,-1, 0 }
};
private static short[,] flou = new short[,]
{
{ 1, 1, 1 },
{ 1, 1, 1 },
{ 1, 1, 1 }
};
public static short[,] identityFilter = new short[,]
private static short[,] renforcement = new short[,]
{
{ 0, 0, 0 },
{ 0, 1, 0 },
{-1, 1, 0 },
{ 0, 0, 0 }
};
public static short[,] edgeDetect1Filter = new short[,]
{
{ 1, 0, -1 },
{ 0, 0, 0 },
{ -1, 0, 1 }
};
public static short[,] edgeDetect2Filter = new short[,]
private static short[,] detection = new short[,]
{
{ 0, 1, 0 },
{ 1, -4, 1 },
{ 1,-4, 1 },
{ 0, 1, 0 }
};
public static short[,] edgeDetect3Filter = new short[,]
{
{ -1, -1, -1 },
{ -1, 8, -1 },
{ -1, -1, -1 }
};
public static short[,] sharpenFilter = new short[,]
private static short[,] repoussage = new short[,]
{
{ 0, -1, 0 },
{ -1, 5, -1 },
{ 0, -1, 0 }
{-2,-1, 0 },
{-1, 1, 1 },
{ 0, 1, 2 }
};
public static short[,] motionBlueFilter = new short[,]
{
{ 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 1 },
};
public static List<short[,]> Filtres = new List<short[,]>() { contrastPlus, flou, renforcement, detection, repoussage };
}
}
......@@ -61,7 +61,10 @@ namespace S04_Projet
this.bPixelPtr = bPixelPtr;
nbPixel = opt.width * opt.height;
size = filter.GetLength(0);
if (Program.MULTITHREADING)
nbProcessors = Math.Min(Environment.ProcessorCount, 8);
else
nbProcessors = 1;
}
else throw new Exception("Impossible d'utiliser ce constructeur pour ce type d'opération");
}
......@@ -161,15 +164,6 @@ namespace S04_Projet
int start = nbPixel / nbProcessors * (int)i;
int end = nbPixel / nbProcessors * ((int)i + 1);
/*double param = (double)i;
int start = (int)(Math.Log(param) * nbPixel);
int end;
if (param + stepSize < Math.E) end = (int)(Math.Log(param + stepSize) * nbPixel);
else end = nbPixel;
Console.WriteLine((double)i + "Start : " + start);
Console.WriteLine((double)i + "End : " + end);*/
byte[,] rMatrix = new byte[size, size];
byte[,] gMatrix = new byte[size, size];
byte[,] bMatrix = new byte[size, size];
......
......@@ -83,9 +83,35 @@ namespace S04_Projet
DEBUG = true;
else if (args[i] == "--multithreading" || args[i] == "-MT")
MULTITHREADING = true;
//else if (args[i] == "--multithreadingLoad" || args[i] == "-MTL")
// MULTITHREADING_LOAD = true;
else if (args[i] == "--") ;
else if (args[i] == "--filter" || args[i] == "-f")
{
increment = 2;
int choix = 0;
switch(args[i+1].ToLower())
{
case "flou":
case "blur":
choix = 1;
break;
case "edgedetection":
case "detectionbord":
choix = 3;
break;
case "renforcement":
case "reinforcement":
choix = 2;
break;
case "repoussage":
case "spinning":
choix = 4;
break;
case "constraste":
case "constrast":
choix = 0;
break;
}
img = img.Filter(Filter.Filtres[choix], Filter.Facteurs[choix]);
};
if (DEBUG)
{
......
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -i img\flocon.bmp -f flou
)
\ No newline at end of file
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -MT -i img\flocon.bmp -f flou
)
\ No newline at end of file
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