Решение на Работа с картинки от Деница Петрова

Обратно към всички решения

Към профила на Деница Петрова

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 12 успешни тест(а)
  • 0 неуспешни тест(а)

Код

from collections import Counter
def extract_shades(color, pixels):
return [pixel[color] for pixel in pixels]
def rotate_right(image):
return list(zip(*image[::-1]))
def rotate_left(image):
return list(zip(*image))[::-1]
def invert(image):
pixels = [[[255-elem for elem in pixel] for pixel in row] for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def lighten(image, number):
pixels = [[[int(elem+number*(255-elem))
for elem in pixel]for pixel in row]for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def darken(image, number):
pixels = [[[int(elem-number*elem)
for elem in pixel] for pixel in row] for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def create_histogram(image):
pixels = [pixel for row in image for pixel in row]
red = dict(Counter(extract_shades(0, pixels)))
green = dict(Counter(extract_shades(1, pixels)))
blue = dict(Counter(extract_shades(2, pixels)))
return {'red': red, 'green': green, 'blue': blue}

Лог от изпълнението

............
----------------------------------------------------------------------
Ran 12 tests in 0.087s

OK

История (2 версии и 1 коментар)

Деница обнови решението на 13.03.2016 10:54 (преди над 5 години)

+from collections import Counter
+
+
+def extract(color, pixels):
+ return [pixel[color] for pixel in pixels]
+
+
+def rotate_right(image):
+ return list(zip(*image[::-1]))
+
+
+def rotate_left(image):
+ return list(zip(*image))[::-1]
+
+
+def invert(image):
+ pixels = [[[255-elem for elem in pixel] for pixel in row] for row in image]
+ return [[tuple(pixel) for pixel in row] for row in pixels]
+
+
+def lighten(image, number):
+ pixels = [[[int(elem+number*(255-elem))
+ for elem in pixel]for pixel in row]for row in image]
+ return [[tuple(pixel) for pixel in row] for row in pixels]
+
+
+def darken(image, number):
+ pixels = [[[int(elem-number*elem)
+ for elem in pixel] for pixel in row] for row in image]
+ return [[tuple(pixel) for pixel in row] for row in pixels]
+
+
+def create_histogram(image):
+ pixels = [pixel for row in image for pixel in row]
+ red = dict(Counter(extract(0, pixels)))
+ green = dict(Counter(extract(1, pixels)))
+ blue = dict(Counter(extract(2, pixels)))
+ return {'red': red, 'green': green, 'blue': blue}

Деница обнови решението на 14.03.2016 10:37 (преди над 5 години)

from collections import Counter
-def extract(color, pixels):
+def extract_shades(color, pixels):
return [pixel[color] for pixel in pixels]
def rotate_right(image):
return list(zip(*image[::-1]))
def rotate_left(image):
return list(zip(*image))[::-1]
def invert(image):
pixels = [[[255-elem for elem in pixel] for pixel in row] for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def lighten(image, number):
pixels = [[[int(elem+number*(255-elem))
for elem in pixel]for pixel in row]for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def darken(image, number):
pixels = [[[int(elem-number*elem)
for elem in pixel] for pixel in row] for row in image]
return [[tuple(pixel) for pixel in row] for row in pixels]
def create_histogram(image):
pixels = [pixel for row in image for pixel in row]
- red = dict(Counter(extract(0, pixels)))
- green = dict(Counter(extract(1, pixels)))
- blue = dict(Counter(extract(2, pixels)))
+ red = dict(Counter(extract_shades(0, pixels)))
+ green = dict(Counter(extract_shades(1, pixels)))
+ blue = dict(Counter(extract_shades(2, pixels)))
return {'red': red, 'green': green, 'blue': blue}