Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Blatt5 Algo Aufgaben Python
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dimitri Tayo Fongang Wembe
Blatt5 Algo Aufgaben Python
Commits
00f85327
Commit
00f85327
authored
Jun 6, 2023
by
Dimitri Tayo Fongang Wembe
Browse files
Options
Downloads
Patches
Plain Diff
complete funktions for imgutils
parent
6459ba53
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
imgutils.py
+57
-4
57 additions, 4 deletions
imgutils.py
with
57 additions
and
4 deletions
imgutils.py
+
57
−
4
View file @
00f85327
...
@@ -35,7 +35,13 @@ def image2pixels(image):
...
@@ -35,7 +35,13 @@ def image2pixels(image):
A List containing all ``(R, G, B)``-values of the ``image`` together
A List containing all ``(R, G, B)``-values of the ``image`` together
with the coordinates ``(X, Y)`` of the respective pixel.
with the coordinates ``(X, Y)`` of the respective pixel.
"""
"""
pass
# TODO
# TODO
m
,
n
,
k
=
np
.
shape
(
image
)
result
=
[]
for
i
in
range
(
m
):
for
j
in
range
(
n
):
result
.
append
((
image
[
i
][
j
][
0
],
image
[
i
][
j
][
1
],
image
[
i
][
j
][
2
],
j
,
i
))
return
result
def
pixels2image
(
pixels
):
def
pixels2image
(
pixels
):
...
@@ -54,7 +60,19 @@ def pixels2image(pixels):
...
@@ -54,7 +60,19 @@ def pixels2image(pixels):
A NumPy-Array of type ``uint8`` and shape (M, N, 3) representing
A NumPy-Array of type ``uint8`` and shape (M, N, 3) representing
the image given by ``pixels``.
the image given by ``pixels``.
"""
"""
pass
# TODO
# TODO
m
,
n
=
(
0
,
0
)
for
t
in
pixels
:
if
m
<
t
[
4
]:
m
=
t
[
4
]
if
n
<
t
[
3
]:
n
=
t
[
3
]
image
=
np
.
zeros
((
m
+
1
,
n
+
1
,
3
))
for
t
in
pixels
:
image
[
t
[
4
]][
t
[
3
]][
0
]
=
t
[
0
]
image
[
t
[
4
]][
t
[
3
]][
1
]
=
t
[
1
]
image
[
t
[
4
]][
t
[
3
]][
2
]
=
t
[
2
]
return
image
def
bounding_box
(
pixels
):
def
bounding_box
(
pixels
):
...
@@ -71,7 +89,30 @@ def bounding_box(pixels):
...
@@ -71,7 +89,30 @@ def bounding_box(pixels):
A tuple containing the respective minimum and maximum values of
A tuple containing the respective minimum and maximum values of
each color in the image represented by ``pixels``.
each color in the image represented by ``pixels``.
"""
"""
pass
# TODO
# TODO
Rmin
=
pixels
[
0
][
0
]
Rmax
=
pixels
[
0
][
0
]
Gmin
=
pixels
[
0
][
1
]
Gmax
=
pixels
[
0
][
1
]
Bmin
=
pixels
[
0
][
2
]
Bmax
=
pixels
[
0
][
2
]
for
p
in
pixels
:
if
Rmin
>
p
[
0
]:
Rmin
=
p
[
0
]
if
Rmax
<
p
[
0
]:
Rmax
=
p
[
0
]
if
Gmin
>
p
[
1
]:
Gmin
=
p
[
1
]
if
Gmax
<
p
[
1
]:
Gmax
=
p
[
1
]
if
Bmin
>
p
[
2
]:
Bmin
=
p
[
2
]
if
Bmax
<
p
[
2
]:
Bmax
=
p
[
2
]
return
((
Rmin
,
Rmax
),
(
Gmin
,
Gmax
),
(
Bmin
,
Bmax
))
def
color_average
(
pixels
):
def
color_average
(
pixels
):
...
@@ -87,7 +128,19 @@ def color_average(pixels):
...
@@ -87,7 +128,19 @@ def color_average(pixels):
A tuple containing the average value of red, green, and blue
A tuple containing the average value of red, green, and blue
color values in the image represented by ``pixels``.
color values in the image represented by ``pixels``.
"""
"""
pass
# TODO
# TODO
Ravg
,
Gavg
,
Bavg
=
(
0
,
0
,
0
)
for
p
in
pixels
:
Ravg
+=
p
[
0
]
Gavg
+=
p
[
1
]
Bavg
+=
p
[
2
]
listLen
=
len
(
pixels
)
Ravg
/=
listLen
Gavg
/=
listLen
Bavg
/=
listLen
return
(
np
.
uint8
(
round
(
Ravg
,
0
)),
np
.
uint8
(
round
(
Gavg
,
0
)),
np
.
uint8
(
round
(
Bavg
,
0
)))
def
main
():
def
main
():
...
...
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