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
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
60d355fe
Commit
60d355fe
authored
1 year ago
by
Dimitri Tayo Fongang Wembe
Browse files
Options
Downloads
Patches
Plain Diff
complete funktions for mcut
parent
a0cf1272
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
mcut.py
+33
-2
33 additions, 2 deletions
mcut.py
with
33 additions
and
2 deletions
mcut.py
+
33
−
2
View file @
60d355fe
...
...
@@ -25,7 +25,16 @@ def cut_dimension(bbox):
number 0 stands for red, 1 stands for green, and 2 stands for blue.
In case of a draw, the smaller value has to be returned.
"""
pass
# TODO
# TODO
differences
=
[]
for
component
in
bbox
:
difference
=
component
[
1
]
-
component
[
0
]
differences
.
append
(
difference
)
max_difference
=
max
(
differences
)
longest_side_index
=
differences
.
index
(
max_difference
)
return
longest_side_index
def
recursive_median_cut
(
pixels
,
N
,
bbox
=
False
):
...
...
@@ -54,7 +63,29 @@ def recursive_median_cut(pixels, N, bbox=False):
if
N
==
0
:
(
ravg
,
gavg
,
bavg
)
=
imgutils
.
color_average
(
pixels
)
return
[(
ravg
,
gavg
,
bavg
,
pixel
[
3
],
pixel
[
4
])
for
pixel
in
pixels
]
pass
# TODO
# TODO
if
bbox
:
longest_side
=
cut_dimension
(
bbox
)
else
:
bbox
=
imgutils
.
bounding_box
(
pixels
)
longest_side
=
cut_dimension
(
bbox
)
# Sortiere die Pixel basierend auf der längsten Seite
sorted_pixels
=
sorted
(
pixels
,
key
=
lambda
pixel
:
pixel
[
longest_side
])
# Teile die sortierten Pixel in zwei Hälften
half
=
len
(
sorted_pixels
)
//
2
first_half
=
sorted_pixels
[:
half
]
second_half
=
sorted_pixels
[
half
:]
# Rufe den Median Cut-Algorithmus rekursiv für beide Hälften auf
first_half
=
recursive_median_cut
(
first_half
,
N
-
1
,
False
)
second_half
=
recursive_median_cut
(
second_half
,
N
-
1
,
False
)
# Füge die beiden Hälften wieder zusammen
result
=
first_half
+
second_half
return
result
def
median_cut
(
image
,
ncuts
=
8
):
...
...
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