Решение на Работа с картинки от Марио Даскалов

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

Към профила на Марио Даскалов

Резултати

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

Код

from collections import defaultdict
def rotate_left(picture):
rotated_picture = list(zip(*picture))
rotated_picture.reverse()
return rotated_picture
def rotate_right(picture):
rotated_picture = list(picture)
rotated_picture.reverse()
rotated_picture = list(zip(*rotated_picture))
return rotated_picture
def invert(picture):
def invert_color(pixel):
return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
return [list(map(invert_color, row)) for row in picture]
def lighten(picture, factor):
def lighten_color(pixel):
red = pixel[0] + factor * (255 - pixel[0])
green = pixel[1] + factor * (255 - pixel[1])
blue = pixel[2] + factor * (255 - pixel[2])
return (int(red), int(green), int(blue))
return [list(map(lighten_color, row)) for row in picture]
def darken(picture, factor):
def darken_color(pixel):
red = pixel[0] - factor * pixel[0]
green = pixel[1] - factor * pixel[1]
blue = pixel[2] - factor * pixel[2]
return (int(red), int(green), int(blue))
return [list(map(darken_color, row)) for row in picture]
def create_histogram(picture):
def color_value(index):
color_statistics = defaultdict(int)
color_values = [pixel[index] for row in picture for pixel in row]
for value in color_values:
color_statistics[value] += 1
return color_statistics
return {
'red': color_value(0),
'green': color_value(1),
'blue': color_value(2)
}

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.086s

OK

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

Марио обнови решението на 14.03.2016 12:04 (преди над 5 години)

+from collections import defaultdict
+
+
+def rotate_left(picture):
+ rotated_picture = list(zip(*picture))
+ rotated_picture.reverse()
+ return rotated_picture
+
+
+def rotate_right(picture):
+ rotated_picture = list(picture)
+ rotated_picture.reverse()
+ rotated_picture = list(zip(*rotated_picture))
+ return rotated_picture
+
+
+def invert(picture):
+ def invert_color(pixel):
+ return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
+
+ return [list(map(invert_color, row)) for row in picture]
+
+
+def lighten(picture, factor):
+ def lighten_color(pixel):
+ red = pixel[0] + factor * (255 - pixel[0])
+ green = pixel[1] + factor * (255 - pixel[1])
+ blue = pixel[2] + factor * (255 - pixel[2])
+ return (int(red), int(green), int(blue))
+
+ return [list(map(lighten_color, row)) for row in picture]
+
+
+def darken(picture, factor):
+ def darken_color(pixel):
+ red = pixel[0] - factor * pixel[0]
+ green = pixel[1] - factor * pixel[1]
+ blue = pixel[2] - factor * pixel[2]
+ return (int(red), int(green), int(blue))
+
+ return [list(map(darken_color, row)) for row in picture]
+
+
+def create_histogram(picture):
+ def color_value(index):
+ color_statistics = defaultdict(int)
+ color_values = [pixel[index] for row in picture for pixel in row]
+
+ for value in color_values:
+ color_statistics[value] += 1
+
+ return color_statistics
+
+ return {
+ 'red': color_value(0),
+ 'green': color_value(1),
+ 'blue': color_value(2)
+ }