Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-KINADINOVA-Dariya
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
Dariya Kinadinova
AP-KINADINOVA-Dariya
Commits
6e29373d
Commit
6e29373d
authored
1 year ago
by
Kinadinova Dariya
Browse files
Options
Downloads
Patches
Plain Diff
class Block: average_color
parent
74f6804d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
projet/Block.py
+13
-0
13 additions, 0 deletions
projet/Block.py
projet/Decouper_Image.py
+0
-50
0 additions, 50 deletions
projet/Decouper_Image.py
projet/color.py
+37
-24
37 additions, 24 deletions
projet/color.py
with
50 additions
and
74 deletions
projet/Block.py
+
13
−
0
View file @
6e29373d
...
...
@@ -5,6 +5,7 @@
"""
from
PIL
import
Image
,
ImageDraw
from
color.py
import
*
class
Block
:
def
__init__
(
self
,
image
):
...
...
@@ -17,6 +18,18 @@ class Block:
"""
self
.
image
=
image
self
.
width
,
self
.
height
=
image
.
size
def
average_color
(
self
):
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
"""
colors
=
liste_col
(
self
.
image
,
(
0
,
0
),
(
self
.
width
-
1
,
self
.
height
-
1
))
return
avg_col
(
colors
)
def
is_uniform
(
self
,
coordinates
:
tuple
()):
"""
à_remplacer_par_ce_que_fait_la_fonction
...
...
This diff is collapsed.
Click to expand it.
projet/Decouper_Image.py
+
0
−
50
View file @
6e29373d
...
...
@@ -25,57 +25,7 @@ def decouper(file: str) -> list[Image]:
l
=
[
block_1
,
block_2
,
block_3
,
block_4
]
return
l
def
avg_col
(
l
:
list
)
->
tuple
():
"""
renvoie la couleur moyenne d
'
une liste de couleurs
Précondition :
Exemple(s) :
$$$ avg_col([(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)])
(236, 210, 111)
"""
c1
=
0
c2
=
0
c3
=
0
for
col
in
l
:
c1
+=
col
[
0
]
c2
+=
col
[
1
]
c3
+=
col
[
2
]
avg1
=
c1
//
len
(
l
)
avg2
=
c2
//
len
(
l
)
avg3
=
c3
//
len
(
l
)
return
(
avg1
,
avg2
,
avg3
)
def
list_col
(
im
:
Image
,
left_top
:
tuple
(),
right_bottom
:
tuple
())
->
list
[
int
]:
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$ list_col(Image.open(
'
calbuth.png
'
), (0,0), (1, 1))
[(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)]
"""
x_min
,
y_min
=
left_top
x_max
,
y_max
=
right_bottom
return
[
im
.
getpixel
((
x
,
y
))
for
x
in
range
(
x_max
+
1
)
for
y
in
range
(
y_max
+
1
)]
def
is_col_close
(
color1
:
tuple
(),
color2
:
tuple
())
->
bool
:
"""
returns True if the distance between two colors is not more than 30,
returns False if the distance is more than 30
Précondition :
Exemple(s) :
$$$ is_col_close((230, 210, 210), (236, 210, 211))
True
$$$ is_col_close((66, 135, 245), (103, 179, 82))
False
"""
if
(
abs
(
color1
[
0
]
-
color2
[
0
])
<=
30
)
and
(
abs
(
color1
[
1
]
-
color2
[
1
])
<=
30
)
and
(
abs
(
color1
[
2
]
-
color2
[
2
])
<=
30
):
res
=
True
else
:
res
=
False
return
res
...
...
This diff is collapsed.
Click to expand it.
projet/color.py
+
37
−
24
View file @
6e29373d
...
...
@@ -4,44 +4,57 @@
from
PIL
import
Image
,
ImageDraw
# Color manipulation
def
avg_col
(
l
:
list
[
int
])
->
list
[
int
]
:
"""
déterminer
la couleur moyenne d
'
une liste de couleurs
def
avg_col
(
l
:
list
)
->
tuple
()
:
"""
renvoie
la couleur moyenne d
'
une liste de couleurs
Précondition :
Exemple(s) :
$$$
$$$ avg_col([(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)])
(236, 210, 111)
"""
n_col
=
len
(
l
)
if
n_col
==
0
:
return
None
else
:
c1
=
0
c2
=
0
c3
=
0
for
i
in
l
:
c1
=
c1
+
l
[
0
]
c2
=
c2
+
l
[
1
]
c3
=
c3
+
l
[
2
]
avg1
=
c1
/
n_col
avg2
=
c2
/
n_col
avg3
=
c3
/
n_col
c1
=
0
c2
=
0
c3
=
0
for
col
in
l
:
c1
+=
col
[
0
]
c2
+=
col
[
1
]
c3
+=
col
[
2
]
avg1
=
c1
//
len
(
l
)
avg2
=
c2
//
len
(
l
)
avg3
=
c3
//
len
(
l
)
return
(
avg1
,
avg2
,
avg3
)
def
list
e
_col
(
im
:
Image
,
left_top
:
tuple
(),
right_bottom
:
tuple
())
->
list
[
int
]:
def
list_col
(
im
:
Image
,
left_top
:
tuple
(),
right_bottom
:
tuple
())
->
list
[
int
]:
"""
à_remplacer_par_ce_que_fait_la_fonction
Précondition :
Exemple(s) :
$$$
$$$ list_col(Image.open(
'
calbuth.png
'
), (0,0), (1, 1))
[(236, 210, 111), (236, 210, 111), (236, 210, 111), (236, 210, 111)]
"""
x_min
,
y_min
=
left_top
x_max
,
y_max
=
right_bottom
l
=
[]
for
i
in
range
((
x_max
+
1
)
*
(
y_max
+
1
)):
l
.
append
(
im
.
getpixel
((
x
,
y
)
for
x
in
range
(
x_max
+
1
)
for
y
in
range
(
y_max
+
1
)))
return
l
return
[
im
.
getpixel
((
x
,
y
))
for
x
in
range
(
x_max
+
1
)
for
y
in
range
(
y_max
+
1
)]
def
is_col_close
(
color1
:
tuple
(),
color2
:
tuple
())
->
bool
:
"""
returns True if the distance between two colors is not more than 30,
returns False if the distance is more than 30
Précondition :
Exemple(s) :
$$$ is_col_close((230, 210, 210), (236, 210, 211))
True
$$$ is_col_close((66, 135, 245), (103, 179, 82))
False
"""
if
(
abs
(
color1
[
0
]
-
color2
[
0
])
<=
30
)
and
(
abs
(
color1
[
1
]
-
color2
[
1
])
<=
30
)
and
(
abs
(
color1
[
2
]
-
color2
[
2
])
<=
30
):
res
=
True
else
:
res
=
False
return
res
\ 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