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
7984ce1e
Commit
7984ce1e
authored
Feb 19, 2018
by
Théophile BORNON
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shrinking okay, convolution WIP
parent
6c5baa1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
173 additions
and
16 deletions
+173
-16
Display.cs
S04_Projet/Display.cs
+18
-0
MyImage.cs
S04_Projet/MyImage.cs
+72
-9
Options.cs
S04_Projet/Options.cs
+0
-2
Pixel.cs
S04_Projet/Pixel.cs
+33
-0
Program.cs
S04_Projet/Program.cs
+50
-5
No files found.
S04_Projet/Display.cs
View file @
7984ce1e
...
...
@@ -18,6 +18,7 @@ namespace S04_Projet
Rotate270
,
GrayScaleLinear
,
GrayScaleLuminosity
,
Shrink
,
Save
}
...
...
@@ -93,6 +94,7 @@ namespace S04_Projet
"Rotation à 270°"
,
"Passage à une image en nuances de gris (linéairement)"
,
"Passage à une image en nuances de gris (luminosité)"
,
"Rétrécissement de l'image"
,
"Sauvegarder"
};
...
...
@@ -161,6 +163,22 @@ namespace S04_Projet
if
(
ope
==
Operation
.
GrayScaleLinear
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
grayFilterType
.
LINEAR
);
else
if
(
ope
==
Operation
.
GrayScaleLuminosity
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
grayFilterType
.
LUMINOSITY
);
}
else
if
(
ope
==
Operation
.
Shrink
)
{
bool
retry
=
false
;
int
input
;
do
{
if
(
retry
)
Console
.
WriteLine
(
"Saisie incorrecte"
);
Console
.
WriteLine
(
"Veuillez saisir le facteur de rétrécissement souhaité"
);
retry
=
!
int
.
TryParse
(
Console
.
ReadLine
(),
out
input
);
}
while
(
retry
&&
input
>=
2
);
sw
.
Restart
();
output
=
img
.
Shrink
(
input
);
}
else
if
(
ope
==
Operation
.
Save
)
{
string
path
;
...
...
S04_Projet/MyImage.cs
View file @
7984ce1e
...
...
@@ -69,7 +69,7 @@ namespace S04_Projet
#
region
File
info
opt
.
fileInfoHeaderSize
=
EndianToInt
(
file
,
14
,
18
);
opt
.
width
=
EndianToInt
(
file
,
18
,
22
);
opt
.
stride
=
opt
.
width
+
(
opt
.
width
%
4
!=
0
?
4
-
(
opt
.
width
%
4
)
:
0
);
// A CHANGER
opt
.
padding
=
opt
.
width
%
4
;
opt
.
height
=
EndianToInt
(
file
,
22
,
26
);
opt
.
colorPlanesNb
=
EndianToInt
(
file
,
26
,
28
);
opt
.
bitsPerPixel
=
EndianToInt
(
file
,
28
,
30
);
...
...
@@ -125,7 +125,7 @@ namespace S04_Projet
private
void
FromImageToFile
(
string
output
)
{
int
nbPixel
=
(
opt
.
height
*
opt
.
width
);
int
bytesNumber
=
nbPixel
*
3
+
opt
.
offset
;
// Multiply by 3 because 3 bytes / pixel
int
bytesNumber
=
nbPixel
*
3
+
opt
.
offset
+
opt
.
height
*
opt
.
padding
;
// Multiply by 3 because 3 bytes / pixel
byte
[]
file
=
new
byte
[
bytesNumber
];
#
region
HEADER
...
...
@@ -153,9 +153,13 @@ namespace S04_Projet
#
endregion
#
region
Pixel
array
int
x
;
int
y
;
for
(
int
i
=
0
;
i
<
nbPixel
;
i
++)
{
MixArrays
(
file
,
Pixels
[
i
%
opt
.
width
,
i
/
opt
.
width
].
getBGR
(),
54
+
(
i
*
3
));
x
=
i
%
opt
.
width
;
y
=
i
/
opt
.
width
;
MixArrays
(
file
,
Pixels
[
x
,
y
].
getBGR
(),
opt
.
offset
+
(
i
*
3
)
+
opt
.
padding
*
y
);
}
#
endregion
...
...
@@ -212,10 +216,69 @@ namespace S04_Projet
}
#
endregion
public
MyImage
Enlarge
(
int
coeff
)
/*
public MyImage Enlarge(int coeff)
{
Options options = opt.Copy();
Pixel
[,]
PixelArr
=
new
Pixel
[
opt
.
width
*
2
,
opt
.
height
*
2
];
options.width *= coeff;
options.height *= coeff;
Pixel[,] PixelArr = new Pixel[opt.width * 2, opt.height * 2];
for (int i = 0; i < options.width * options.height; i++)
{
int x = i % options.width;
int y = i % options.height;
byte[] fromX = Pixels[x, y].getRGB();
byte[] toX;
byte[] toY;
byte[] toXY;
if (x + 1 < options.width) toX = Pixels[x + 1, y].getRGB();
if (y + 1 < options.height) toY = Pixels[x, y + 1].getRGB();
if (y + 1 < options.height && x + 1 < options.width) toXY = Pixels[x + 1, y + 1].getRGB();
}
}*/
public
MyImage
Shrink
(
int
coeff
)
{
Options
options
=
opt
.
Copy
();
options
.
width
/=
coeff
;
options
.
height
/=
coeff
;
options
.
padding
=
options
.
width
%
4
;
options
.
imgSize
=
options
.
width
*
options
.
height
*
3
+
options
.
padding
*
options
.
height
;
options
.
fileSize
=
options
.
imgSize
+
options
.
fileInfoHeaderSize
;
Pixel
[,]
PixelArr
=
new
Pixel
[
options
.
width
,
options
.
height
];
int
x0
,
y0
,
x
,
y
;
int
[]
rgb
;
byte
[]
_rgb
;
for
(
int
i
=
0
;
i
<
options
.
width
*
options
.
height
;
i
++)
{
x0
=
i
%
options
.
width
;
y0
=
i
/
options
.
width
;
rgb
=
new
int
[]
{
0
,
0
,
0
};
for
(
int
j
=
0
;
j
<
coeff
*
coeff
;
j
++)
{
x
=
x0
*
coeff
+
j
%
coeff
;
y
=
y0
*
coeff
+
j
/
coeff
;
_rgb
=
Pixels
[
x
,
y
].
getRGB
();
for
(
int
k
=
0
;
k
<
3
;
k
++)
rgb
[
k
]
+=
_rgb
[
k
];
}
for
(
int
j
=
0
;
j
<
3
;
j
++)
rgb
[
j
]
=
(
byte
)(
rgb
[
j
]
/
(
coeff
*
coeff
));
PixelArr
[
x0
,
y0
]
=
new
Pixel
(
rgb
);
}
return
new
MyImage
(
options
,
PixelArr
);
}
public
MyImage
ToGrayScale
(
byte
scale
,
grayFilterType
type
)
...
...
@@ -242,7 +305,7 @@ namespace S04_Projet
int
size
=
filter
.
GetLength
(
0
);
Options
options
=
opt
.
Copy
();
int
nbPixel
=
options
.
height
*
options
.
width
;
Pixel
[,]
PixelArr
=
new
Pixel
[
opt
.
width
,
opt
.
height
];
Pixel
[,]
PixelArr
=
new
Pixel
[
opt
ions
.
width
,
options
.
height
];
int
x
,
y
;
int
[,]
rMatrix
,
gMatrix
,
bMatrix
;
...
...
@@ -280,7 +343,7 @@ namespace S04_Projet
{
int
[,]
matrix
=
new
int
[
size
,
size
];
for
(
int
i
=
0
;
i
<
Math
.
Pow
(
size
,
2
)
;
i
++)
for
(
int
i
=
0
;
i
<
size
*
size
;
i
++)
{
int
x
=
x0
+
(
i
%
size
)
-
((
size
-
1
)
/
2
);
int
y
=
y0
+
(
i
/
size
)
-
((
size
-
1
)
/
2
);
...
...
@@ -299,10 +362,10 @@ namespace S04_Projet
return
matrix
;
}
p
rivate
byte
ConvolutionalResult
(
int
[,]
matrix
,
int
[,]
conv
,
int
size
,
double
factor
)
p
ublic
static
byte
ConvolutionalResult
(
int
[,]
matrix
,
int
[,]
conv
,
int
size
,
double
factor
)
{
int
r
=
0
;
for
(
int
i
=
0
;
i
<
Math
.
Pow
(
size
,
2
)
;
i
++)
for
(
int
i
=
0
;
i
<
size
*
size
;
i
++)
{
int
x
=
i
%
size
;
int
y
=
i
/
size
;
...
...
S04_Projet/Options.cs
View file @
7984ce1e
...
...
@@ -11,7 +11,6 @@ namespace S04_Projet
public
int
fileInfoHeaderSize
;
public
int
width
;
public
int
height
;
public
int
stride
;
public
int
colorPlanesNb
;
public
int
bitsPerPixel
;
public
int
compressionMethod
;
...
...
@@ -33,7 +32,6 @@ namespace S04_Projet
options
.
fileInfoHeaderSize
=
fileInfoHeaderSize
;
options
.
width
=
width
;
options
.
height
=
height
;
options
.
stride
=
stride
;
options
.
padding
=
padding
;
options
.
colorPlanesNb
=
colorPlanesNb
;
options
.
bitsPerPixel
=
bitsPerPixel
;
...
...
S04_Projet/Pixel.cs
View file @
7984ce1e
...
...
@@ -12,6 +12,10 @@ namespace S04_Projet
public
byte
g
{
get
;
private
set
;
}
public
byte
b
{
get
;
private
set
;
}
public
double
H
{
get
;
private
set
;
}
public
double
S
{
get
;
private
set
;
}
public
double
L
{
get
;
private
set
;
}
/// <summary>
/// Prend les trois couleurs en paramètres
/// </summary>
...
...
@@ -47,6 +51,13 @@ namespace S04_Projet
b
=
rgb
[
2
];
}
public
Pixel
(
int
[]
rgb
)
{
r
=
(
byte
)
rgb
[
0
];
g
=
(
byte
)
rgb
[
1
];
b
=
(
byte
)
rgb
[
2
];
}
/// <summary>
/// Retourne un tableau contenant les valeurs RGB du pixel
/// </summary>
...
...
@@ -89,5 +100,27 @@ namespace S04_Projet
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
()
{
double
rH
=
r
/
255.0
;
double
gH
=
g
/
255.0
;
double
bH
=
b
/
255.0
;
double
Cmax
=
Math
.
Max
(
Math
.
Max
(
rH
,
gH
),
bH
);
double
Cmin
=
Math
.
Min
(
Math
.
Min
(
rH
,
gH
),
bH
);
double
delta
=
Cmax
-
Cmin
;
L
=
(
Cmin
+
Cmax
)
/
2.0
;
if
(
delta
==
0
)
S
=
0
;
else
S
=
delta
/
(
1.0
-
Math
.
Abs
(
2.0
*
L
-
1
));
if
(
delta
==
0
)
H
=
0
;
else
if
(
Cmax
==
rH
)
H
=
60
*
(((
gH
-
bH
)
/
delta
)
%
6
);
else
if
(
Cmax
==
gH
)
H
=
60
*
(((
bH
-
rH
)
/
delta
)
+
2
);
else
H
=
60
*
(((
rH
-
gH
)
/
delta
)
+
4
);
}
}
}
S04_Projet/Program.cs
View file @
7984ce1e
...
...
@@ -13,6 +13,55 @@ namespace S04_Projet
{
static
void
Main
(
string
[]
args
)
{
int
[,]
boxBlurFilter
=
new
int
[,]
{
{
1
,
1
,
1
},
{
1
,
1
,
1
},
{
1
,
1
,
1
}
};
int
[,]
identityFilter
=
new
int
[,]
{
{
0
,
0
,
0
},
{
0
,
1
,
0
},
{
0
,
0
,
0
}
};
int
[,]
edgeDetect1Filter
=
new
int
[,]
{
{
1
,
0
,
-
1
},
{
0
,
0
,
0
},
{
-
1
,
0
,
1
}
};
int
[,]
edgeDetect2Filter
=
new
int
[,]
{
{
0
,
1
,
0
},
{
1
,
-
4
,
1
},
{
0
,
1
,
0
}
};
int
[,]
edgeDetect3Filter
=
new
int
[,]
{
{
-
1
,
-
1
,
-
1
},
{
-
1
,
8
,
-
1
},
{
-
1
,
-
1
,
-
1
}
};
int
[,]
sharpenFilter
=
new
int
[,]
{
{
0
,
-
1
,
0
},
{
-
1
,
5
,
-
1
},
{
0
,
-
1
,
0
}
};
MyImage
imgg
=
new
MyImage
(
"img/ex.bmp"
);
//imgg.ApplyConvFilter(identityFilter, 1).Save("id.bmp");
imgg
.
ApplyConvFilter
(
edgeDetect1Filter
,
1
).
Save
(
"edge1.bmp"
);
//imgg.ApplyConvFilter(edgeDetect2Filter, 1).Save("edge2.bmp");
imgg
.
ApplyConvFilter
(
edgeDetect3Filter
,
1
).
Save
(
"edge3.bmp"
);
//imgg.ApplyConvFilter(sharpenFilter, 1).Save("sharpen.bmp");
//imgg.ApplyConvFilter(boxBlurFilter, (double)1/9).Save("blur.bmp");
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
Console
.
WriteLine
(
"#############################################################"
);
Console
.
WriteLine
(
"### Bienvenue ###"
);
...
...
@@ -31,14 +80,10 @@ namespace S04_Projet
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
WriteLine
(
"Image sauvegardée en {0}ms!"
,
Display
.
elapsedTime
);
//Console.Clear();
Console
.
Read
();
#
region
Test
/*MyImage imgRotate90 = img.Rotate90();
imgRotate90.Save("90.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