Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-belkacemi-melissa
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Melissa Belkacemi
AP-belkacemi-melissa
Commits
95ca2ce4
Commit
95ca2ce4
authored
1 year ago
by
Belkacemi Melissa
Browse files
Options
Downloads
Patches
Plain Diff
decoupe
parent
d4af03fe
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PJ/decoupe.py
+56
-0
56 additions, 0 deletions
PJ/decoupe.py
with
56 additions
and
0 deletions
PJ/decoupe.py
0 → 100644
+
56
−
0
View file @
95ca2ce4
from
PIL
import
Image
,
ImageDraw
from
bloc
import
*
from
couleur
import
*
def
decoupe
(
image
:
Image
,
p_hg
,
p_bd
,
n
:
int
)
->
Bloc
:
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :n>=0
"""
if
n
>
0
:
b1
,
b2
,
b3
,
b4
=
quatre_blocs
(
image
,
hg
,
bd
)
decoupe
(
b1
,
n
-
1
,
b1
.
pixel_hg
,
b1
.
pixel_bd
)
decoupe
(
b2
,
n
-
1
,
b2
.
pixel_hg
,
b2
.
pixel_bd
)
decoupe
(
b3
,
n
-
1
,
b3
.
pixel_hg
,
b3
.
pixel_bd
)
decoupe
(
b4
,
n
-
1
,
b4
.
pixel_hg
,
b4
.
pixel_bd
)
if
sont_proches
(
b1
,
b2
,
b3
,
b4
):
return
(
Bloc
(
couleur_moyenne
([
b1
.
couleur
,
b2
.
couleur
,
b3
.
couleur
,
b4
.
couleur
]),
b1
.
pixel_hg
,
b4
.
pixel_bd
))
else
:
return
(
Bloc
((
0
,
0
,
0
),
b1
.
pixel_hg
,
b4
.
pixel_bd
,
b1
,
b2
,
b3
,
b4
))
else
:
couleurs
=
[
im_rgb
.
getpixel
((
i
,
j
))
for
i
in
range
(
hg
[
0
],
1
+
bd
[
0
])
for
j
in
range
(
hg
[
1
],
1
+
bd
[
1
])]
coul_moyenne
=
couleur_moyenne
(
couleurs
)
return
Bloc
(
coul_moyenne
,(
0
,
0
),(
bd
[
0
],
bd
[
1
]))
def
quatre_blocs
(
im
:
Image
,
hg
:
tuple
[
int
,
int
],
bd
:
tuple
[
int
,
int
])
->
tuple
[
Bloc
,
Bloc
,
Bloc
,
Bloc
]:
"""
découpe une image en 4 blocs
"""
pixel_hg1
=
hg
pixel_bd1
=
((
bd
[
0
]
+
hg
[
0
])
//
2
,(
bd
[
1
]
+
hg
[
1
])
//
2
)
pixel_hg2
=
((
bd
[
0
]
+
hg
[
0
])
//
2
,
hg
[
1
])
pixel_bd2
=
(
bd
[
0
],(
bd
[
1
]
+
hg
[
1
])
//
2
)
pixel_hg3
=
(
hg
[
0
],(
bd
[
1
]
+
hg
[
1
])
//
2
)
pixel_bd3
=
((
bd
[
0
]
+
hg
[
0
])
//
2
,
bd
[
1
])
pixel_hg4
=
((
bd
[
0
]
+
hg
[
0
])
//
2
,(
bd
[
1
]
+
hg
[
1
])
//
2
)
pixel_bd4
=
bd
couleurs1
=
[
im
.
getpixel
((
i
,
j
))
for
i
in
range
(
pixel_hg1
[
0
],
1
+
pixel_bd1
[
0
])
for
j
in
range
(
pixel_hg1
[
1
],
1
+
pixel_bd1
[
1
])]
couleurs2
=
[
im
.
getpixel
((
i
,
j
))
for
i
in
range
(
pixel_hg2
[
0
],
1
+
pixel_bd2
[
0
])
for
j
in
range
(
pixel_hg2
[
1
],
1
+
pixel_bd2
[
1
])]
couleurs3
=
[
im
.
getpixel
((
i
,
j
))
for
i
in
range
(
pixel_hg3
[
0
],
1
+
pixel_bd3
[
0
])
for
j
in
range
(
pixel_hg3
[
1
],
1
+
pixel_bd3
[
1
])]
couleurs4
=
[
im
.
getpixel
((
i
,
j
))
for
i
in
range
(
pixel_hg4
[
0
],
1
+
pixel_bd4
[
0
])
for
j
in
range
(
pixel_hg4
[
1
],
1
+
pixel_bd4
[
1
])]
return
(
Bloc
(
couleur_moyenne
(
couleurs1
),
pixel_hg1
,
pixel_bd1
),
Bloc
(
couleur_moyenne
(
couleurs2
),
pixel_hg2
,
pixel_bd2
),
Bloc
(
couleur_moyenne
(
couleurs3
),
pixel_hg3
,
pixel_bd3
),
Bloc
(
couleur_moyenne
(
couleurs4
),
pixel_hg4
,
pixel_bd4
))
im
=
Image
.
open
(
'
images/calbuth.png
'
)
t
=
im
.
size
hg
=
(
0
,
0
)
bd
=
(
t
[
0
]
-
1
,
t
[
1
]
-
1
)
im_rgb
=
im
.
convert
(
'
RGB
'
)
b
=
decoupe
(
im_rgb
,
hg
,
bd
,
1
)
\ No newline at end of file
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