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
bdf3478e
Commit
bdf3478e
authored
Feb 20, 2018
by
BORNON Théophile
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout des commentaires
parent
6e8940d3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
73 deletions
+150
-73
Display.cs
S04_Projet/Display.cs
+7
-4
MyImage.cs
S04_Projet/MyImage.cs
+124
-22
Options.cs
S04_Projet/Options.cs
+4
-0
Pixel.cs
S04_Projet/Pixel.cs
+14
-7
Program.cs
S04_Projet/Program.cs
+1
-40
No files found.
S04_Projet/Display.cs
View file @
bdf3478e
...
...
@@ -67,7 +67,7 @@ namespace S04_Projet
elapsedTime
=
sw
.
ElapsedMilliseconds
;
lastOperationMessage
=
"Image chargée en "
+
elapsedTime
+
"ms"
;
fileInfos
=
image
.
t
oString
();
fileInfos
=
image
.
T
oString
();
return
image
;
}
...
...
@@ -160,8 +160,8 @@ namespace S04_Projet
}
while
(
retry
&&
input
>=
2
&&
input
<=
255
);
sw
.
Restart
();
if
(
ope
==
Operation
.
GrayScaleLinear
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
g
rayFilterType
.
LINEAR
);
else
if
(
ope
==
Operation
.
GrayScaleLuminosity
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
g
rayFilterType
.
LUMINOSITY
);
if
(
ope
==
Operation
.
GrayScaleLinear
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
G
rayFilterType
.
LINEAR
);
else
if
(
ope
==
Operation
.
GrayScaleLuminosity
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
G
rayFilterType
.
LUMINOSITY
);
}
else
if
(
ope
==
Operation
.
Shrink
)
{
...
...
@@ -203,11 +203,14 @@ namespace S04_Projet
sw
.
Stop
();
elapsedTime
=
sw
.
ElapsedMilliseconds
;
lastOperationMessage
=
String
.
Format
(
"Opération {0}, effectuée avec succès en {1}ms"
,
ope
,
elapsedTime
);
fileInfos
=
(
output
!=
null
)
?
output
.
t
oString
()
:
""
;
fileInfos
=
(
output
!=
null
)
?
output
.
T
oString
()
:
""
;
return
output
;
}
/// <summary>
/// Ecran d'attente
/// </summary>
public
static
void
WaitingScreen
()
{
Console
.
Write
(
"Traitement de l'image en cours"
);
...
...
S04_Projet/MyImage.cs
View file @
bdf3478e
...
...
@@ -13,7 +13,7 @@ namespace S04_Projet
private
int
nbProcessors
;
byte
[]
file
;
public
enum
g
rayFilterType
public
enum
G
rayFilterType
{
LINEAR
,
LUMINOSITY
...
...
@@ -26,6 +26,10 @@ namespace S04_Projet
B
}
/// <summary>
/// Constructeur prenant en paramètre un chemin vers un fichier BMP 24 bits
/// </summary>
/// <param name="path">Chemin vers un fichier BMP</param>
public
MyImage
(
string
path
)
{
opt
=
new
Options
();
...
...
@@ -48,40 +52,52 @@ namespace S04_Projet
}
}
/// <summary>
/// Constructeur prenant en paramètres un ficher BMP sous forme d'octets
/// </summary>
/// <param name="file">Ficher BMP en octets</param>
public
MyImage
(
byte
[]
file
)
{
this
.
file
=
file
;
FromFileToImage
();
}
/// <summary>
/// Instancie l'objet à partir d'une matrice de pixel et d'options
/// </summary>
/// <param name="opt">Options de l'image</param>
/// <param name="Pixels">Matrice de pixels constituant l'image</param>
public
MyImage
(
Options
opt
,
Pixel
[,]
Pixels
)
{
this
.
opt
=
opt
;
this
.
Pixels
=
Pixels
;
}
/// <summary>
/// Charge une image. Multithreading WIP. Dépendante de la fonction LoadImage pour le multithreading
/// </summary>
private
void
FromFileToImage
()
{
opt
=
new
Options
();
#
region
Header
opt
.
format
=
(
char
)
file
[
0
]
+
""
+
(
char
)
file
[
1
];
opt
.
fileSize
=
EndianToInt
(
file
,
2
,
6
);
opt
.
offset
=
EndianToInt
(
file
,
10
,
14
);
opt
.
fileSize
=
EndianToInt
(
file
,
2
);
opt
.
offset
=
EndianToInt
(
file
,
10
);
#
endregion
#
region
File
info
opt
.
fileInfoHeaderSize
=
EndianToInt
(
file
,
14
,
18
);
opt
.
width
=
EndianToInt
(
file
,
18
,
22
);
opt
.
fileInfoHeaderSize
=
EndianToInt
(
file
,
14
);
opt
.
width
=
EndianToInt
(
file
,
18
);
opt
.
padding
=
opt
.
width
%
4
;
opt
.
height
=
EndianToInt
(
file
,
22
,
2
6
);
opt
.
colorPlanesNb
=
EndianToInt
(
file
,
26
,
28
);
opt
.
bitsPerPixel
=
EndianToInt
(
file
,
28
,
30
);
opt
.
compressionMethod
=
EndianToInt
(
file
,
30
,
34
);
opt
.
imgSize
=
EndianToInt
(
file
,
34
,
38
);
opt
.
horizontalRes
=
EndianToInt
(
file
,
38
,
42
);
opt
.
VerticalRes
=
EndianToInt
(
file
,
42
,
46
);
opt
.
nbColor
=
EndianToInt
(
file
,
46
,
50
);
opt
.
nbImportantColor
=
EndianToInt
(
file
,
50
,
54
);
opt
.
height
=
EndianToInt
(
file
,
226
);
opt
.
colorPlanesNb
=
EndianToInt
(
file
,
26
);
opt
.
bitsPerPixel
=
EndianToInt
(
file
,
28
);
opt
.
compressionMethod
=
EndianToInt
(
file
,
30
);
opt
.
imgSize
=
EndianToInt
(
file
,
34
);
opt
.
horizontalRes
=
EndianToInt
(
file
,
38
);
opt
.
VerticalRes
=
EndianToInt
(
file
,
42
);
opt
.
nbColor
=
EndianToInt
(
file
,
46
);
opt
.
nbImportantColor
=
EndianToInt
(
file
,
50
);
#
endregion
#
region
Pixel
array
...
...
@@ -129,6 +145,11 @@ namespace S04_Projet
#
endregion
}
/// <summary>
/// Fonction utilisée par FromImageToFile() pour le multithreading. Parcours le fichier pour en extraire
/// la matrice de pixels
/// </summary>
/// <param name="i">Numero du thread</param>
private
void
LoadImage
(
object
i
)
{
int
start
=
opt
.
width
*
opt
.
height
/
nbProcessors
*
(
int
)
i
;
...
...
@@ -149,6 +170,10 @@ namespace S04_Projet
}
}
/// <summary>
/// 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
)
{
int
nbPixel
=
(
opt
.
height
*
opt
.
width
);
...
...
@@ -193,12 +218,20 @@ namespace S04_Projet
File
.
WriteAllBytes
(
output
,
file
);
}
/// <summary>
/// Sauvegarde l'image
/// </summary>
/// <param name="output">Chemin de sortie de l'image</param>
public
void
Save
(
string
output
)
{
FromImageToFile
(
output
);
}
#
region
Rotations
/// <summary>
/// Tourne l'image de 90° dans le sens horaire
/// </summary>
/// <returns>Image tournée de 90° dans le sens horaire</returns>
public
MyImage
Rotate90
()
{
Options
options
=
opt
.
Copy
();
...
...
@@ -214,6 +247,10 @@ namespace S04_Projet
return
new
MyImage
(
options
,
PixelArr
);
}
/// <summary>
/// Tourne l'image de 180° dans le sens horaire
/// </summary>
/// <returns>Image tournée de 180° dans le sens horaire</returns>
public
MyImage
Rotate180
()
{
Options
options
=
opt
.
Copy
();
...
...
@@ -227,6 +264,10 @@ namespace S04_Projet
return
new
MyImage
(
options
,
PixelArr
);
}
/// <summary>
/// Tourne l'image de 270° dans le sens horaire
/// </summary>
/// <returns>Image tournée de 270° dans le sens horaire</returns>
public
MyImage
Rotate270
()
{
Options
options
=
opt
.
Copy
();
...
...
@@ -243,7 +284,12 @@ namespace S04_Projet
}
#
endregion
/*public MyImage Enlarge(int coeff)
/// <summary>
/// Agrandit l'image par rapport au coefficient passé en paramètre. WIP
/// </summary>
/// <param name="coeff">Coefficient d'agrandissement de l'image</param>
/// <returns>Image élargie</returns>
public
MyImage
Enlarge
(
int
coeff
)
{
Options
options
=
opt
.
Copy
();
options
.
width
*=
coeff
;
...
...
@@ -265,8 +311,14 @@ namespace S04_Projet
}
}*/
return
null
;
}
/// <summary>
/// Rétrécit l'image par rapport au coefficient passé en paramètres
/// </summary>
/// <param name="coeff">Coefficient de rétrécissement de l'image</param>
/// <returns>Image rétrécie</returns>
public
MyImage
Shrink
(
int
coeff
)
{
Options
options
=
opt
.
Copy
();
...
...
@@ -308,7 +360,13 @@ namespace S04_Projet
return
new
MyImage
(
options
,
PixelArr
);
}
public
MyImage
ToGrayScale
(
byte
scale
,
grayFilterType
type
)
/// <summary>
/// Passe l'image en nuances de gris
/// </summary>
/// <param name="scale">Nombre de nuances de gris désirées (entre 2 et 255) (2 = noir et blanc)</param>
/// <param name="type">Type de transformation. Linéaire ou en fonction de la luminosité de la couleur</param>
/// <returns>Image en nuances de gris</returns>
public
MyImage
ToGrayScale
(
byte
scale
,
GrayFilterType
type
)
{
Options
options
=
opt
.
Copy
();
opt
.
nbColor
=
scale
;
...
...
@@ -317,14 +375,20 @@ namespace S04_Projet
{
int
x
=
i
%
opt
.
width
;
int
y
=
i
/
opt
.
width
;
if
(
type
==
g
rayFilterType
.
LINEAR
)
if
(
type
==
G
rayFilterType
.
LINEAR
)
PixelArr
[
x
,
y
]
=
Pixels
[
x
,
y
].
getGrayScale
(
scale
);
else
if
(
type
==
g
rayFilterType
.
LUMINOSITY
)
else
if
(
type
==
G
rayFilterType
.
LUMINOSITY
)
PixelArr
[
x
,
y
]
=
Pixels
[
x
,
y
].
getGrayScaleLuminosity
(
scale
);
}
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
)
...
...
@@ -366,6 +430,14 @@ namespace S04_Projet
}
}
/// <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
];
...
...
@@ -391,6 +463,14 @@ namespace S04_Projet
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
;
;
...
...
@@ -403,13 +483,25 @@ namespace S04_Projet
else
return
(
byte
)
r
;
}
private
static
int
EndianToInt
(
byte
[]
arr
,
int
from
,
int
to
)
/// <summary>
/// Passe d'un nombre au format Endian à un nombre entier
/// </summary>
/// <param name="arr">Tableau d'octets contenant le nombre au format endian</param>
/// <param name="from">Point de départ (inclu)</param>
/// <returns>Nombre entier</returns>
private
static
int
EndianToInt
(
byte
[]
arr
,
int
from
)
{
int
somme
=
0
;
for
(
int
i
=
from
;
i
<
to
;
i
++)
somme
+=
(
arr
[
i
]
<<
((
i
-
from
)
*
8
));
for
(
int
i
=
from
;
i
<
from
+
4
;
i
++)
somme
+=
(
arr
[
i
]
<<
((
i
-
from
)
*
8
));
return
somme
;
}
/// <summary>
/// Passe un nombre du format entier au format endian
/// </summary>
/// <param name="val">Valeur de l'entier</param>
/// <returns>Tableau d'octets représentant l'entier au format endian</returns>
private
static
byte
[]
IntToEndian
(
int
val
)
{
byte
[]
endian
=
new
byte
[
4
];
...
...
@@ -418,6 +510,12 @@ namespace S04_Projet
return
endian
;
}
/// <summary>
/// Ajoute le contenu du tableau 2 au tableau 1 à partir du point de départ
/// </summary>
/// <param name="arr">Tableau 1</param>
/// <param name="toAdd">Tableau 2</param>
/// <param name="start">Point de départ</param>
private
static
void
MixArrays
(
byte
[]
arr
,
byte
[]
toAdd
,
int
start
)
{
for
(
int
i
=
start
;
i
<
start
+
toAdd
.
Length
;
i
++)
...
...
@@ -426,7 +524,11 @@ namespace S04_Projet
}
}
public
string
toString
()
/// <summary>
/// Chaine de charactères décrivant l'objet
/// </summary>
/// <returns>Chaine de charactères décrivant l'objet</returns>
public
override
string
ToString
()
{
string
str
=
""
;
...
...
S04_Projet/Options.cs
View file @
bdf3478e
...
...
@@ -26,6 +26,10 @@ namespace S04_Projet
public
Options
()
{
}
/// <summary>
/// Return a new instance of Options with the same parameters
/// </summary>
/// <returns>New option instance</returns>
public
Options
Copy
()
{
Options
options
=
new
Options
();
...
...
S04_Projet/Pixel.cs
View file @
bdf3478e
...
...
@@ -16,6 +16,10 @@ namespace S04_Projet
public
double
S
{
get
;
private
set
;
}
public
double
L
{
get
;
private
set
;
}
public
void
SetR
(
byte
r
)
=>
this
.
r
=
r
;
public
void
SetG
(
byte
g
)
=>
this
.
g
=
g
;
public
void
SetB
(
byte
b
)
=>
this
.
b
=
b
;
/// <summary>
/// Prend les trois couleurs en paramètres
/// </summary>
...
...
@@ -51,6 +55,10 @@ namespace S04_Projet
b
=
rgb
[
2
];
}
/// <summary>
/// Créer un pixel à partir d'un tableau contenant les couleurs rouge, vert, bleu (respectivement)
/// </summary>
/// <param name="rgb">Tableau composé dans cet ordre des couleurs rouge, vert, bleu</param>
public
Pixel
(
int
[]
rgb
)
{
r
=
(
byte
)
rgb
[
0
];
...
...
@@ -97,11 +105,10 @@ namespace S04_Projet
return
new
Pixel
(
total
);
}
public
void
SetR
(
byte
r
)
{
this
.
r
=
r
;
}
public
void
SetG
(
byte
g
)
{
this
.
g
=
g
;
}
public
void
SetB
(
byte
b
)
{
this
.
b
=
b
;
}
private
void
computeHSl
()
/// <summary>
/// Calcul les valeurs de variables HSL (Hue, Saturation, Lightness)
/// </summary>
private
void
computeHSL
()
{
double
rH
=
r
/
255.0
;
double
gH
=
g
/
255.0
;
...
...
S04_Projet/Program.cs
View file @
bdf3478e
...
...
@@ -17,46 +17,7 @@ namespace S04_Projet
MyImage
img
=
new
MyImage
(
"img/lena.bmp"
);
img
.
Save
(
"output.bmp"
);
/*short[,] boxBlurFilter = new short[,] {
{1,1,1 },
{1,1,1 },
{1,1,1 }
};
short[,] identityFilter = new short[,]
{
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 0 }
};
short[,] edgeDetect1Filter = new short[,]
{
{ 1, 0, -1 },
{ 0, 0, 0 },
{ -1, 0, 1 }
};
short[,] edgeDetect2Filter = new short[,]
{
{ 0, 1, 0 },
{ 1, -4, 1 },
{ 0, 1, 0 }
};
short[,] edgeDetect3Filter = new short[,]
{
{ -1, -1, -1 },
{ -1, 8, -1 },
{ -1, -1, -1 }
};
short[,] sharpenFilter = new short[,]
{
{ 0, -1, 0 },
{ -1, 5, -1 },
{ 0, -1, 0 }
};
/*
MyImage imgg = new MyImage("img/coco.bmp");
imgg.ApplyConvFilter(identityFilter, 1).Save("id.bmp");
...
...
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