Skip to content
Snippets Groups Projects
Commit 60d355fe authored by Dimitri Tayo Fongang Wembe's avatar Dimitri Tayo Fongang Wembe
Browse files

complete funktions for mcut

parent a0cf1272
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment