Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imageProcessing
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ecole
imageProcessing
Commits
7e7e39a8
Commit
7e7e39a8
authored
Feb 23, 2018
by
BORNON Théophile
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better faster stronger
parent
77e62751
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
207 deletions
+124
-207
ImageProcessing.exe
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
+0
-0
MultiThreadedTask.cs
S04_Projet/MultiThreadedTask.cs
+25
-11
MyImage.cs
S04_Projet/MyImage.cs
+95
-192
Program.cs
S04_Projet/Program.cs
+4
-4
ImageProcessing.exe
S04_Projet/bin/Debug/ImageProcessing.exe
+0
-0
No files found.
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
View file @
7e7e39a8
No preview for this file type
S04_Projet/MultiThreadedTask.cs
View file @
7e7e39a8
...
...
@@ -3,7 +3,7 @@ using System.Threading;
namespace
S04_Projet
{
class
MultiThreadedTask
unsafe
class
MultiThreadedTask
{
#
region
Attributs
public
enum
Operation
...
...
@@ -20,6 +20,8 @@ namespace S04_Projet
}
private
byte
[]
file
;
private
byte
[]
NewRMatrix
,
NewGMatrix
,
NewBMatrix
;
byte
*
rPixelPtr
,
gPixelPtr
,
bPixelPtr
;
private
int
nbPixel
;
private
int
nbProcessors
;
private
Options
opt
;
...
...
@@ -49,8 +51,11 @@ namespace S04_Projet
this
.
opt
=
opt
;
this
.
filter
=
filter
;
this
.
factor
=
factor
;
this
.
rPixelPtr
=
rPixelPtr
;
this
.
gPixelPtr
=
gPixelPtr
;
this
.
bPixelPtr
=
bPixelPtr
;
size
=
filter
.
GetLength
(
0
);
nbProcessors
=
Environment
.
ProcessorCount
;
nbProcessors
=
4
;
}
public
void
Start
()
...
...
@@ -96,10 +101,14 @@ namespace S04_Projet
#
endregion
#
region
Filter
public
void
ApplyFilter
()
public
MyImage
ApplyFilter
()
{
int
pixelNumber
=
opt
.
width
*
opt
.
height
;
int
pixelPerThread
=
pixelNumber
/
nbProcessors
;
NewRMatrix
=
new
byte
[
pixelNumber
];
NewGMatrix
=
new
byte
[
pixelNumber
];
NewBMatrix
=
new
byte
[
pixelNumber
];
Thread
[]
threads
=
new
Thread
[
nbProcessors
];
Console
.
WriteLine
(
"Creating {0} thread(s)"
,
nbProcessors
);
...
...
@@ -114,9 +123,11 @@ namespace S04_Projet
{
threads
[
i
].
Join
();
}
return
new
MyImage
(
opt
,
NewRMatrix
,
NewGMatrix
,
NewBMatrix
);
}
p
ublic
unsafe
void
ApplyFilterTask
(
object
i
)
p
rivate
unsafe
void
ApplyFilterTask
(
object
i
)
{
int
x
,
y
;
int
start
=
opt
.
width
*
opt
.
height
/
nbProcessors
*
(
int
)
i
;
...
...
@@ -142,6 +153,9 @@ namespace S04_Projet
g
=
ConvolutionalResult
(
gMatrixPtr
,
filterPtr
,
size
,
factor
);
b
=
ConvolutionalResult
(
bMatrixPtr
,
filterPtr
,
size
,
factor
);
NewRMatrix
[
j
]
=
r
;
NewGMatrix
[
j
]
=
g
;
NewBMatrix
[
j
]
=
b
;
}
}
}
...
...
@@ -167,12 +181,12 @@ namespace S04_Projet
if
(
y
<
0
)
y
=
0
;
else
if
(
y
>=
opt
.
height
)
y
=
opt
.
height
-
1
;
if
(
rgb
==
RGB
.
R
)
;
// *(matrixPtr + i) = Pixels[x, y].r
;
else
if
(
rgb
==
RGB
.
G
)
;
// *(matrixPtr + i) = Pixels[x, y].g
;
else
if
(
rgb
==
RGB
.
B
)
;
// *(matrixPtr + i) = Pixels[x, y].b
;
if
(
rgb
==
RGB
.
R
)
*(
matrixPtr
+
i
)
=
*(
rPixelPtr
+
x
+
y
*
opt
.
width
)
;
else
if
(
rgb
==
RGB
.
G
)
*(
matrixPtr
+
i
)
=
*(
gPixelPtr
+
x
+
y
*
opt
.
width
)
;
else
if
(
rgb
==
RGB
.
B
)
*(
matrixPtr
+
i
)
=
*(
bPixelPtr
+
x
+
y
*
opt
.
width
)
;
}
}
...
...
S04_Projet/MyImage.cs
View file @
7e7e39a8
...
...
@@ -9,6 +9,7 @@ namespace S04_Projet
private
Options
opt
;
byte
[]
rPixels
,
gPixels
,
bPixels
;
byte
[]
file
;
private
int
nbProcessors
;
public
enum
GrayFilterType
{
...
...
@@ -16,7 +17,7 @@ namespace S04_Projet
LUMINOSITY
}
p
rivate
enum
RGB
p
ublic
enum
RGB
{
R
,
G
,
...
...
@@ -49,6 +50,7 @@ namespace S04_Projet
{
if
(
file
.
Length
!=
0
)
{
nbProcessors
=
Environment
.
ProcessorCount
;
FromFileToImage
();
}
}
...
...
@@ -146,7 +148,7 @@ namespace S04_Projet
/// Sauvegarde l'image vers le chemin passé en paramètres
/// </summary>
/// <param name="output">Chemin de sortie de l'image</param>
private
void
FromImageToFile
(
string
output
)
private
unsafe
void
FromImageToFile
(
string
output
)
{
int
nbPixel
=
(
opt
.
height
*
opt
.
width
);
int
bytesNumber
=
nbPixel
*
3
+
opt
.
offset
+
opt
.
height
*
opt
.
padding
;
// Multiply by 3 because 3 bytes / pixel
...
...
@@ -180,14 +182,17 @@ namespace S04_Projet
#
region
Pixel
array
int
x
;
int
y
;
fixed
(
byte
*
filePtr
=
file
)
{
for
(
int
i
=
0
;
i
<
nbPixel
;
i
++)
{
x
=
i
%
opt
.
width
;
y
=
i
/
opt
.
width
;
file
[
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
]
=
bPixels
[
i
];
file
[
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
1
]
=
gPixels
[
i
];
file
[
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
2
]
=
rPixels
[
i
];
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
)
=
bPixels
[
i
];
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
1
)
=
gPixels
[
i
];
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
2
)
=
rPixels
[
i
];
}
}
#
endregion
...
...
@@ -360,116 +365,14 @@ namespace S04_Projet
return new MyImage(options, PixelArr);
}*/
/// <summary>
/// Applique un filtre de convolution à l'image
/// </summary>
/// <param name="filter">Filtre de convolution</param>
/// <param name="factor">Facteur de normalisation</param>
/// <returns>Image avec le filtre de convolution appliqué</returns>
/*public MyImage ApplyConvFilter(short[,] filter, double factor)
{
if (filter.GetLength(0) == filter.GetLength(1) && filter.GetLength(0) % 2 == 1)
{
int size = filter.GetLength(0);
Options options = opt.Copy();
int nbPixel = options.height * options.width;
Pixel[,] PixelArr = new Pixel[options.width, options.height];
if (!Program.MULTITHREADING)
{
int x, y;
byte[,] rMatrix, gMatrix, bMatrix;
byte r, g, b;
for (int i = 0; i < nbPixel; i++)
public
unsafe
MyImage
Filter
(
short
[,]
filter
,
double
factor
)
{
x = i % options.width;
y = i / options.width;
rMatrix = GetMatrix(x, y, size, RGB.R);
gMatrix = GetMatrix(x, y, size, RGB.G);
bMatrix = GetMatrix(x, y, size, RGB.B);
r = ConvolutionalResult(rMatrix, filter, size, factor);
g = ConvolutionalResult(gMatrix, filter, size, factor);
b = ConvolutionalResult(bMatrix, filter, size, factor);
PixelArr[x, y] = new Pixel(r, g, b);
}
}
else
fixed
(
byte
*
rPixelPtr
=
rPixels
,
gPixelPtr
=
gPixels
,
bPixelPtr
=
bPixels
)
{
MultiThreadedTask FilterImageTask =
new MultiThreadedTask(MultiThreadedTask.Operation.Filter, Pixels, opt, filter, factor);
FilterImageTask.Start();
Pixel[,] _Pixels = FilterImageTask.getFilteredMatrix();
return new MyImage(opt, _Pixels);
MultiThreadedTask
multiThreadedTask
=
new
MultiThreadedTask
(
MultiThreadedTask
.
Operation
.
Filter
,
rPixelPtr
,
gPixelPtr
,
bPixelPtr
,
opt
,
filter
,
factor
);
return
multiThreadedTask
.
ApplyFilter
();
}
return new MyImage(options, PixelArr);
}
else if (filter.GetLength(0) != filter.GetLength(1))
{
throw new Exception("Matrice non carrée");
}
else
{
throw new Exception("Matrice de taille paire");
}
}
/// <summary>
/// Retourne la matrice de pixels de taille size ,de milieu (x0,y0) et de couleur RGB
/// </summary>
/// <param name="x0">Coordonnée verticale du pixel milieu</param>
/// <param name="y0">Coordonnée horizontale du pixel milieu</param>
/// <param name="size">Taille de la matrice de pixel désirée</param>
/// <param name="rgb">Couleur souhaitée</param>
/// <returns>Matrice de pixels de taille size ,de milieu (x0,y0) et de couleur RGB</returns>
private byte[,] GetMatrix(int x0, int y0, int size, RGB rgb)
{
byte[,] matrix = new byte[size, size];
for (int i = 0; i < size * size; i++)
{
int x = x0 + (i % size) - ((size - 1) / 2);
int y = y0 + (i / size) - ((size - 1) / 2);
if (x < 0) x = 0;
else if (x >= opt.width) x = opt.width - 1;
if (y < 0) y = 0;
else if (y >= opt.height) y = opt.height - 1;
if (rgb == RGB.R)
matrix[(i % size), (i / size)] = Pixels[x, y].r;
else if (rgb == RGB.G)
matrix[(i % size), (i / size)] = Pixels[x, y].g;
else if (rgb == RGB.B)
matrix[(i % size), (i / size)] = Pixels[x, y].b;
}
return matrix;
}
/// <summary>
/// Calcul convolutionnel
/// </summary>
/// <param name="matrix">Matrice</param>
/// <param name="conv">Convolution</param>
/// <param name="size">Taille du filtre</param>
/// <param name="factor">Factor de normalisation</param>
/// <returns>Résultat du calcul convolutinnel</returns>
public static byte ConvolutionalResult(byte[,] matrix, short[,] conv, int size, double factor)
{
short r = 0; ;
for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++)
r += (short)(matrix[x, y] * conv[x, y]);
r = (short)Math.Round(r * factor);
if (r > 255) return 255;
else if (r < 0) return 0;
else return (byte)r;
}*/
/// <summary>
/// Passe d'un nombre au format Endian à un nombre entier
...
...
S04_Projet/Program.cs
View file @
7e7e39a8
...
...
@@ -60,12 +60,12 @@ namespace S04_Projet
Stopwatch
sw
=
new
Stopwatch
();
MyImage
imgg
=
new
MyImage
(
"img/image.bmp"
);
Console
.
WriteLine
(
"Loading done"
);
sw
.
Start
();
MyImage
imgg
=
new
MyImage
(
"img/flocon.bmp"
);
MyImage
newImg
=
imgg
.
Filter
(
sharpenFilter
,
1
);
sw
.
Stop
();
imgg
.
Save
(
"test.bmp"
);
Console
.
WriteLine
(
"Loading done"
);
//imgg.ApplyConvFilter(edgeDetect1Filter, 1);
newImg
.
Save
(
"filter.bmp"
);
Console
.
WriteLine
(
sw
.
ElapsedMilliseconds
);
Console
.
Read
();
...
...
S04_Projet/bin/Debug/ImageProcessing.exe
View file @
7e7e39a8
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment