Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prog_C
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
thibault.chatillo
Prog_C
Commits
4ebf7f62
Commit
4ebf7f62
authored
4 years ago
by
thib
Browse files
Options
Downloads
Patches
Plain Diff
main rdy
parent
c60b1063
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
TP7-image/chien-pasteque.pgm
+0
-0
0 additions, 0 deletions
TP7-image/chien-pasteque.pgm
TP7-image/image.c
+64
-54
64 additions, 54 deletions
TP7-image/image.c
TP7-image/main.c
+54
-10
54 additions, 10 deletions
TP7-image/main.c
with
118 additions
and
64 deletions
TP7-image/chien-pasteque.pgm
0 → 100644
+
0
−
0
View file @
4ebf7f62
File added
This diff is collapsed.
Click to expand it.
TP7-image/image.c
+
64
−
54
View file @
4ebf7f62
...
@@ -10,7 +10,6 @@
...
@@ -10,7 +10,6 @@
// matrix pixels;
// matrix pixels;
// } pgm;
// } pgm;
pgm_error
pmg_read_from_file
(
pgm
*
p
,
char
*
filename
)
{
pgm_error
pmg_read_from_file
(
pgm
*
p
,
char
*
filename
)
{
if
(
NULL
==
filename
||
NULL
==
p
)
{
if
(
NULL
==
filename
||
NULL
==
p
)
{
return
failure
;
return
failure
;
...
@@ -196,7 +195,8 @@ if(NULL== orig || NULL==photomaton){
...
@@ -196,7 +195,8 @@ if(NULL== orig || NULL==photomaton){
pgm_error
pmg_crop
(
pgm
*
crop
,
const
pgm
*
const
orig
,
int
x0
,
int
x1
,
int
y0
,
pgm_error
pmg_crop
(
pgm
*
crop
,
const
pgm
*
const
orig
,
int
x0
,
int
x1
,
int
y0
,
int
y1
)
{
int
y1
)
{
if
(
ok
!=
matrix_extract_submatrix
(
&
crop
->
pixels
,
orig
->
pixels
,
y0
,
y1
,
x0
,
x1
)){
if
(
ok
!=
matrix_extract_submatrix
(
&
crop
->
pixels
,
orig
->
pixels
,
y0
,
y1
,
x0
,
x1
))
{
return
failure
;
return
failure
;
}
}
...
@@ -204,62 +204,72 @@ pgm_error pmg_crop(pgm *crop, const pgm *const orig, int x0, int x1, int y0,
...
@@ -204,62 +204,72 @@ pgm_error pmg_crop(pgm *crop, const pgm *const orig, int x0, int x1, int y0,
return
success
;
return
success
;
}
}
pgm_error
pmg_conv
(
pgm
*
conv
,
const
pgm
*
const
orig
,
const
matrix
*
const
kernel
)
{
int
get_divider
(
const
matrix
*
const
mat
)
{
if
(
NULL
==
orig
||
NULL
==
conv
||
NULL
==
kernel
){
return
failure
;
}
int
divider
=
0
;
int
divider
=
0
;
// get divider
for
(
int
y
=
0
;
y
<
mat
->
m
;
y
++
)
{
for
(
int
y
=
0
;
y
<
kernel
->
m
;
y
++
)
{
// ligne
for
(
int
x
=
0
;
x
<
mat
->
n
;
x
++
)
{
for
(
int
x
=
0
;
x
<
kernel
->
n
;
x
++
)
{
divider
+=
mat
->
data
[
y
][
x
];
divider
+=
kernel
->
data
[
y
][
x
];
}
}
}
}
if
(
divider
<
1
)
{
if
(
divider
<
1
)
{
divider
=
1
;
divider
=
1
;
}
}
return
divider
;
}
pgm_error
pmg_conv
(
pgm
*
conv
,
const
pgm
*
const
orig
,
const
matrix
*
const
kernel
)
{
if
(
NULL
==
orig
||
NULL
==
conv
||
NULL
==
kernel
)
{
return
failure
;
}
matrix_alloc
(
&
(
conv
->
pixels
),
orig
->
pixels
.
m
,
orig
->
pixels
.
n
);
matrix_alloc
(
&
(
conv
->
pixels
),
orig
->
pixels
.
m
,
orig
->
pixels
.
n
);
conv
->
max
=
orig
->
max
;
conv
->
max
=
orig
->
max
;
for
(
int
i
=
0
;
i
<
orig
->
pixels
.
m
;
i
++
)
{
// ligne
for
(
int
j
=
0
;
j
<
orig
->
pixels
.
n
;
j
++
)
{
// col
double
sum
=
0
.
0
;
int
divider
=
get_divider
(
kernel
);
for
(
int
i
=
0
;
i
<
orig
->
pixels
.
m
;
i
++
)
{
for
(
int
j
=
0
;
j
<
orig
->
pixels
.
n
;
j
++
)
{
double
pixel
=
0
.
0
;
for
(
int
y
=
0
;
y
<
kernel
->
m
;
y
++
)
{
// ligne
for
(
int
y
=
0
;
y
<
kernel
->
m
;
y
++
)
{
for
(
int
x
=
0
;
x
<
kernel
->
n
;
x
++
)
{
// col
for
(
int
x
=
0
;
x
<
kernel
->
n
;
x
++
)
{
int
yi
=
i
-
kernel
->
m
/
2
+
y
;
int
yi
=
i
-
kernel
->
m
/
2
+
y
;
int
xj
=
j
-
kernel
->
n
/
2
+
x
;
int
xj
=
j
-
kernel
->
n
/
2
+
x
;
//if pixel is inside matrix
if
(
xj
>=
0
&&
yi
>=
0
&&
xj
<
orig
->
pixels
.
m
&&
if
(
xj
>=
0
&&
yi
>=
0
&&
xj
<
orig
->
pixels
.
m
&&
yi
<
orig
->
pixels
.
n
)
{
yi
<
orig
->
pixels
.
n
)
{
pixel
+=
orig
->
pixels
.
data
[
yi
][
xj
]
*
kernel
->
data
[
y
][
x
];
sum
+=
orig
->
pixels
.
data
[
yi
][
xj
]
*
kernel
->
data
[
y
][
x
];
}
}
}
}
}
}
sum
/=
divider
;
pixel
/=
divider
;
//check pixel's val ->
// printf("%f ",sum);
if
(
pixel
<
0
)
{
if
(
sum
<
0
)
{
pixel
=
0
;
sum
=
0
;
}
else
if
(
pixel
>
conv
->
max
)
{
}
else
if
(
sum
>
conv
->
max
)
{
pixel
=
conv
->
max
;
sum
=
conv
->
max
;
}
}
//
printf("%d\n",(int)sum);
//
set pixel
conv
->
pixels
.
data
[
i
][
j
]
=
(
int
)
sum
;
conv
->
pixels
.
data
[
i
][
j
]
=
(
int
)
pixel
;
}
}
}
}
return
success
;
return
success
;
}
}
pgm_error
pgm_display
(
pgm
p
)
{
pgm_error
pgm_display
(
pgm
p
)
{
struct
gfx_context_t
*
context
=
gfx_create
(
"SDL Display"
,
p
.
pixels
.
m
,
p
.
pixels
.
n
);
struct
gfx_context_t
*
context
=
gfx_create
(
"SDL Display"
,
p
.
pixels
.
m
,
p
.
pixels
.
n
);
if
(
!
context
)
{
if
(
!
context
)
{
fprintf
(
stderr
,
"Graphics initialization failed!
\n
"
);
fprintf
(
stderr
,
"Graphics initialization failed!
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
...
This diff is collapsed.
Click to expand it.
TP7-image/main.c
+
54
−
10
View file @
4ebf7f62
...
@@ -12,8 +12,29 @@ int main() {
...
@@ -12,8 +12,29 @@ int main() {
pgm
out
;
pgm
out
;
matrix
kernel
;
matrix
kernel
;
pmg_read_from_file
(
&
in
,
"
mandrill
.pgm"
);
pmg_read_from_file
(
&
in
,
"
chien-pasteque
.pgm"
);
// https://en.wikipedia.org/wiki/Kernel_(image_processing)
// https://en.wikipedia.org/wiki/Kernel_(image_processing)
pmg_negative
(
&
out
,
&
in
);
pmg_write_to_file
(
&
out
,
"neg.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
pmg_symmetry_hori
(
&
out
,
&
in
);
pmg_write_to_file
(
&
out
,
"symh.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
pmg_symmetry_vert
(
&
out
,
&
in
);
pmg_write_to_file
(
&
out
,
"symv.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
pmg_symmetry_cent
(
&
out
,
&
in
);
pmg_write_to_file
(
&
out
,
"symc.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
pmg_photomaton
(
&
out
,
&
in
);
pmg_write_to_file
(
&
out
,
"photomat.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
pmg_crop
(
&
out
,
&
in
,
50
,
200
,
50
,
200
);
pmg_write_to_file
(
&
out
,
"crop.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
int
sharp
[]
=
{
0
,
-
1
,
0
,
-
1
,
5
,
-
1
,
0
,
-
1
,
0
};
int
sharp
[]
=
{
0
,
-
1
,
0
,
-
1
,
5
,
-
1
,
0
,
-
1
,
0
};
int
blur
[]
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
};
int
blur
[]
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
};
int
edge1
[]
=
{
1
,
0
,
-
1
,
0
,
0
,
0
,
-
1
,
0
,
1
};
int
edge1
[]
=
{
1
,
0
,
-
1
,
0
,
0
,
0
,
-
1
,
0
,
1
};
...
@@ -21,20 +42,43 @@ int main() {
...
@@ -21,20 +42,43 @@ int main() {
int
edge3
[]
=
{
-
1
,
-
1
,
-
1
,
-
1
,
8
,
-
1
,
-
1
,
-
1
,
-
1
};
int
edge3
[]
=
{
-
1
,
-
1
,
-
1
,
-
1
,
8
,
-
1
,
-
1
,
-
1
,
-
1
};
int
blur5x5
[]
=
{
1
,
4
,
6
,
4
,
1
,
4
,
16
,
24
,
16
,
4
,
6
,
24
,
36
,
24
,
6
,
4
,
16
,
24
,
16
,
4
,
1
,
4
,
6
,
4
,
1
};
int
blur5x5
[]
=
{
1
,
4
,
6
,
4
,
1
,
4
,
16
,
24
,
16
,
4
,
6
,
24
,
36
,
24
,
6
,
4
,
16
,
24
,
16
,
4
,
1
,
4
,
6
,
4
,
1
};
matrix_init_from_array
(
&
kernel
,
3
,
3
,
sharp
);
matrix_init_from_array
(
&
kernel
,
3
,
3
,
sharp
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
// pgm_display(out);
pmg_write_to_file
(
&
out
,
"sharp.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
//pmg_negative(&out, &in);
matrix_init_from_array
(
&
kernel
,
3
,
3
,
blur
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_write_to_file
(
&
out
,
"blur.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
pmg_write_to_file
(
&
out
,
"sharp.pgm"
);
matrix_init_from_array
(
&
kernel
,
3
,
3
,
edge1
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_write_to_file
(
&
out
,
"edge1.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
matrix_init_from_array
(
&
kernel
,
3
,
3
,
edge2
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_write_to_file
(
&
out
,
"edge2.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
//matrix_destroy(&tmp.pixels);
matrix_init_from_array
(
&
kernel
,
3
,
3
,
edge3
);
matrix_destroy
(
&
in
.
pixels
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_write_to_file
(
&
out
,
"edge3.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
matrix_destroy
(
&
kernel
);
matrix_init_from_array
(
&
kernel
,
5
,
5
,
blur5x5
);
pmg_conv
(
&
out
,
&
in
,
&
kernel
);
pmg_write_to_file
(
&
out
,
"blur5x5.pgm"
);
matrix_destroy
(
&
out
.
pixels
);
matrix_destroy
(
&
kernel
);
matrix_destroy
(
&
in
.
pixels
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment