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
45249fb9
Commit
45249fb9
authored
Feb 22, 2018
by
BORNON Théophile
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pointers everywhere
parent
19eeb88e
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
68 additions
and
50 deletions
+68
-50
ImageProcessing.exe
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
+0
-0
ImageProcessing.csproj
S04_Projet/ImageProcessing.csproj
+1
-0
MultiThreadedTask.cs
S04_Projet/MultiThreadedTask.cs
+31
-34
MyImage.cs
S04_Projet/MyImage.cs
+18
-15
Pixel.cs
S04_Projet/Pixel.cs
+16
-0
Program.cs
S04_Projet/Program.cs
+2
-1
ImageProcessing.exe
S04_Projet/bin/Debug/ImageProcessing.exe
+0
-0
ImageProcessing.exe.config
S04_Projet/bin/Debug/ImageProcessing.exe.config
+0
-0
S04_Projet.exe
S04_Projet/bin/Debug/S04_Projet.exe
+0
-0
No files found.
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
0 → 100644
View file @
45249fb9
File added
S04_Projet/ImageProcessing.csproj
View file @
45249fb9
...
...
@@ -23,6 +23,7 @@
<WarningLevel>
4
</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<AllowUnsafeBlocks>
true
</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<PlatformTarget>
x64
</PlatformTarget>
...
...
S04_Projet/MultiThreadedTask.cs
View file @
45249fb9
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
namespace
S04_Projet
...
...
@@ -111,9 +108,6 @@ namespace S04_Projet
nbProcessors
=
Environment
.
ProcessorCount
;
int
pixelPerThread
=
pixelNumber
/
nbProcessors
;
Thread
[]
threads
=
new
Thread
[
nbProcessors
];
Console
.
WriteLine
(
"Génération de {0} threads"
,
nbProcessors
);
for
(
int
i
=
0
;
i
<
nbProcessors
;
i
++)
{
threads
[
i
]
=
new
Thread
(
new
ParameterizedThreadStart
(
ApplyFilterTask
));
...
...
@@ -123,34 +117,40 @@ namespace S04_Projet
for
(
int
i
=
0
;
i
<
nbProcessors
;
i
++)
{
threads
[
i
].
Join
();
Console
.
WriteLine
(
"Thread {0} done"
,
i
);
}
}
public
void
ApplyFilterTask
(
object
i
)
public
unsafe
void
ApplyFilterTask
(
object
i
)
{
int
x
,
y
;
int
start
=
opt
.
width
*
opt
.
height
/
nbProcessors
*
(
int
)
i
;
int
end
=
opt
.
width
*
opt
.
height
/
nbProcessors
*
((
int
)
i
+
1
);
byte
[,]
rMatrix
,
gMatrix
,
bMatrix
;
byte
[,]
rMatrix
=
new
byte
[
size
,
size
];
byte
[,]
gMatrix
=
new
byte
[
size
,
size
];
byte
[,]
bMatrix
=
new
byte
[
size
,
size
];
byte
r
,
g
,
b
;
fixed
(
short
*
filterPtr
=
filter
)
{
fixed
(
byte
*
rMatrixPtr
=
rMatrix
,
gMatrixPtr
=
gMatrix
,
bMatrixPtr
=
bMatrix
)
{
for
(
int
j
=
start
;
j
<
end
;
j
++)
{
x
=
j
%
opt
.
width
;
y
=
j
/
opt
.
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
);
GetMatrix
(
x
,
y
,
size
,
RGB
.
R
,
rMatrixPtr
);
GetMatrix
(
x
,
y
,
size
,
RGB
.
G
,
gMatrixPtr
);
GetMatrix
(
x
,
y
,
size
,
RGB
.
B
,
bMatrixPtr
);
r
=
ConvolutionalResult
(
rMatrixPtr
,
filterPtr
,
size
,
factor
);
g
=
ConvolutionalResult
(
gMatrixPtr
,
filterPtr
,
size
,
factor
);
b
=
ConvolutionalResult
(
bMatrixPtr
,
filterPtr
,
size
,
factor
);
NewPixels
[
x
,
y
]
=
new
Pixel
(
r
,
g
,
b
);
}
}
}
}
/// <summary>
/// Retourne la matrice de pixels de taille size ,de milieu (x0,y0) et de couleur RGB
...
...
@@ -160,10 +160,8 @@ namespace S04_Projet
/// <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
)
private
unsafe
void
GetMatrix
(
int
x0
,
int
y0
,
int
size
,
RGB
rgb
,
byte
*
matrixPtr
)
{
byte
[,]
matrix
=
new
byte
[
size
,
size
];
for
(
int
i
=
0
;
i
<
size
*
size
;
i
++)
{
int
x
=
x0
+
(
i
%
size
)
-
((
size
-
1
)
/
2
);
...
...
@@ -175,14 +173,12 @@ namespace S04_Projet
else
if
(
y
>=
opt
.
height
)
y
=
opt
.
height
-
1
;
if
(
rgb
==
RGB
.
R
)
matrix
[(
i
%
size
),
(
i
/
size
)]
=
Pixels
[
x
,
y
].
r
;
*(
matrixPtr
+
i
)
=
Pixels
[
x
,
y
].
r
;
else
if
(
rgb
==
RGB
.
G
)
matrix
[(
i
%
size
),
(
i
/
size
)]
=
Pixels
[
x
,
y
].
g
;
*(
matrixPtr
+
i
)
=
Pixels
[
x
,
y
].
g
;
else
if
(
rgb
==
RGB
.
B
)
matrix
[(
i
%
size
),
(
i
/
size
)]
=
Pixels
[
x
,
y
].
b
;
*(
matrixPtr
+
i
)
=
Pixels
[
x
,
y
].
b
;
}
return
matrix
;
}
/// <summary>
...
...
@@ -193,12 +189,13 @@ namespace S04_Projet
/// <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
)
public
unsafe
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
]);
for
(
int
i
=
0
;
i
<
size
*
size
;
i
++)
r
+=
(
short
)(*(
matrix
+
i
)
*
*(
conv
+
i
));
r
=
(
short
)
Math
.
Round
(
r
*
factor
);
if
(
r
>
255
)
return
255
;
else
if
(
r
<
0
)
return
0
;
...
...
S04_Projet/MyImage.cs
View file @
45249fb9
using
System
;
using
System.IO
;
using
System.Diagnostics
;
using
System.Text
;
using
System.Threading
;
namespace
S04_Projet
{
...
...
@@ -80,15 +78,15 @@ namespace S04_Projet
/// <summary>
/// Charge une image. Multithreading WIP. Dépendante de la fonction LoadImage pour le multithreading
/// </summary>
private
void
FromFileToImage
()
private
unsafe
void
FromFileToImage
()
{
opt
=
new
Options
();
#
region
Header
opt
.
format
=
(
char
)
file
[
0
]
+
""
+
(
char
)
file
[
1
];
opt
.
fileSize
=
EndianToInt
(
file
,
2
);
opt
.
offset
=
EndianToInt
(
file
,
10
);
#
endregion
#
region
File
info
opt
.
fileInfoHeaderSize
=
EndianToInt
(
file
,
14
);
opt
.
width
=
EndianToInt
(
file
,
18
);
...
...
@@ -103,7 +101,6 @@ namespace S04_Projet
opt
.
nbColor
=
EndianToInt
(
file
,
46
);
opt
.
nbImportantColor
=
EndianToInt
(
file
,
50
);
#
endregion
#
region
Pixel
array
int
pixelNumber
=
opt
.
width
*
opt
.
height
;
Pixels
=
new
Pixel
[
opt
.
width
,
opt
.
height
];
...
...
@@ -114,17 +111,22 @@ namespace S04_Projet
{
int
x
,
y
;
byte
r
,
g
,
b
;
fixed
(
byte
*
filePtr
=
file
)
{
for
(
int
i
=
0
;
i
<
pixelNumber
;
i
++)
{
x
=
i
%
opt
.
width
;
y
=
i
/
opt
.
width
;
b
=
file
[
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
];
/*
b = file[i * 3 + opt.padding * y + opt.offset];
g = file[i * 3 + opt.padding * y + opt.offset + 1];
r
=
file
[
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
2
];
r = file[i * 3 + opt.padding * y + opt.offset + 2];*/
b
=
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
);
g
=
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
1
);
r
=
*(
filePtr
+
i
*
3
+
opt
.
padding
*
y
+
opt
.
offset
+
2
);
Pixels
[
x
,
y
]
=
new
Pixel
(
r
,
g
,
b
);
}
}
}
#
endregion
#
region
Multithreading
...
...
@@ -151,6 +153,7 @@ namespace S04_Projet
int
bytesNumber
=
nbPixel
*
3
+
opt
.
offset
+
opt
.
height
*
opt
.
padding
;
// Multiply by 3 because 3 bytes / pixel
byte
[]
file
=
new
byte
[
bytesNumber
];
#
region
HEADER
// FORMAT
ASCIIEncoding
encoding
=
new
ASCIIEncoding
();
...
...
S04_Projet/Pixel.cs
View file @
45249fb9
...
...
@@ -33,6 +33,13 @@ namespace S04_Projet
this
.
b
=
b
;
}
public
unsafe
Pixel
(
byte
*
r
,
byte
*
g
,
byte
*
b
)
{
this
.
r
=
*
r
;
this
.
g
=
*
g
;
this
.
b
=
*
b
;
}
/// <summary>
/// Assigne une même valeur à toutes les couleurs
/// </summary>
...
...
@@ -75,6 +82,15 @@ namespace S04_Projet
return
new
byte
[]
{
r
,
g
,
b
};
}
public
unsafe
byte
*
getRGBPtr
()
{
unsafe
{
fixed
(
byte
*
ptr
=
new
byte
[]
{
r
,
g
,
b
})
return
ptr
;
}
}
public
byte
[]
getBGR
()
{
return
new
byte
[]
{
b
,
g
,
r
};
...
...
S04_Projet/Program.cs
View file @
45249fb9
...
...
@@ -58,8 +58,9 @@ namespace S04_Projet
};
#
endregion
MyImage
imgg
=
new
MyImage
(
"flocon.bmp"
);
Stopwatch
sw
=
new
Stopwatch
();
MyImage
imgg
=
new
MyImage
(
"img/flocon.bmp"
);
Console
.
WriteLine
(
"Loading done"
);
sw
.
Start
();
imgg
.
ApplyConvFilter
(
edgeDetect1Filter
,
1
);
...
...
S04_Projet/bin/Debug/ImageProcessing.exe
0 → 100644
View file @
45249fb9
File added
S04_Projet/bin/Debug/
S04_Projet
.exe.config
→
S04_Projet/bin/Debug/
ImageProcessing
.exe.config
View file @
45249fb9
File moved
S04_Projet/bin/Debug/S04_Projet.exe
deleted
100644 → 0
View file @
19eeb88e
File deleted
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