Решение на Работа с картинки от Тина Накова

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

Към профила на Тина Накова

Резултати

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

Код

from collections import Counter
def rotate_left(image):
return [[row[col] for row in image]
for col in range((len(image[0]) - 1), -1, -1)]
def rotate_right(image):
return [[row[col] for row in image[::-1]] for col in range(len(image[0]))]
def invert(image):
width = range(len(image[0]))
return [[tuple((255 - row[col][color]) for color in range(3))
for col in width] for row in image]
def lighten(image, n):
width = range(len(image[0]))
return [[tuple((row[col][color] + int(n * (255 - row[col][color])))
for color in range(3)) for col in width] for row in image]
def darken(image, n):
width = range(len(image[0]))
return [[tuple((row[col][color] - int(n * (row[col][color] - 0)))
for color in range(3)) for col in width] for row in image]
def create_histogram(image):
red_values = get_color_values(image, 0)
green_values = get_color_values(image, 1)
blue_values = get_color_values(image, 2)
return {'red': red_values, 'green': green_values, 'blue': blue_values}
def get_color_values(image, color_index):
width = range(len(image[0]))
return Counter(row[col][color_index] for row in image for col in width)

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

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

OK

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

Тина обнови решението на 11.03.2016 16:43 (преди над 5 години)

+def rotate_left(image):
+ return [[row[col] for row in image]
+ for col in range((len(image[1]) - 1), -1, -1)]
+
+
+def rotate_right(image):
+ return [[row[col] for row in image[::-1]] for col in range(len(image[1]))]
+
+
+def invert(image):
+ width = range(len(image[1]))
+ return [[tuple((255 - row[col][color_index]) for color_index in range(3))
+ for col in width] for row in image]
+
+
+def lighten(image, n):
+ width = range(len(image[1]))
+ return [[tuple((row[col][color] + int(n * (255 - row[col][color])))
+ for color in range(3)) for col in width] for row in image]
+
+
+def darken(image, n):
+ width = range(len(image[1]))
+ return [[tuple((row[col][color] - int(n * (row[col][color] - 0)))
+ for color in range(3)) for col in width] for row in image]
+
+
+def create_histogram(image):
+ red_values = get_values(image, 0)
+ green_values = get_values(image, 1)
+ blue_values = get_values(image, 2)
+
+ return {'red': red_values, 'green': green_values, 'blue': blue_values}
+
+
+def get_values(image, color_index):
+ color_values = {x: 0 for x in range(0, 256)}
+ for key in color_values:
+ for pixels in image:
+ for pixel in pixels:
+ if pixel[color_index] == key:
+ color_values[key] += 1
+
+ return {p: color_values[p] for p in color_values if color_values[p] != 0}

Тина обнови решението на 11.03.2016 23:58 (преди над 5 години)

def rotate_left(image):
return [[row[col] for row in image]
for col in range((len(image[1]) - 1), -1, -1)]
def rotate_right(image):
return [[row[col] for row in image[::-1]] for col in range(len(image[1]))]
def invert(image):
width = range(len(image[1]))
- return [[tuple((255 - row[col][color_index]) for color_index in range(3))
- for col in width] for row in image]
+ return [[tuple((255 - row[col][color]) for color in range(3))
+ for col in width] for row in image]
def lighten(image, n):
width = range(len(image[1]))
return [[tuple((row[col][color] + int(n * (255 - row[col][color])))
- for color in range(3)) for col in width] for row in image]
+ for color in range(3)) for col in width] for row in image]
def darken(image, n):
width = range(len(image[1]))
return [[tuple((row[col][color] - int(n * (row[col][color] - 0)))
- for color in range(3)) for col in width] for row in image]
+ for color in range(3)) for col in width] for row in image]
def create_histogram(image):
red_values = get_values(image, 0)
green_values = get_values(image, 1)
blue_values = get_values(image, 2)
return {'red': red_values, 'green': green_values, 'blue': blue_values}
def get_values(image, color_index):
color_values = {x: 0 for x in range(0, 256)}
- for key in color_values:
- for pixels in image:
- for pixel in pixels:
- if pixel[color_index] == key:
- color_values[key] += 1
+ for pixels in image:
+ for pixel in pixels:
+ color_values[pixel[color_index]] += 1
return {p: color_values[p] for p in color_values if color_values[p] != 0}

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

+from collections import Counter
+
+
def rotate_left(image):
return [[row[col] for row in image]
- for col in range((len(image[1]) - 1), -1, -1)]
+ for col in range((len(image[0]) - 1), -1, -1)]
def rotate_right(image):
- return [[row[col] for row in image[::-1]] for col in range(len(image[1]))]
+ return [[row[col] for row in image[::-1]] for col in range(len(image[0]))]
def invert(image):
- width = range(len(image[1]))
+ width = range(len(image[0]))
return [[tuple((255 - row[col][color]) for color in range(3))
for col in width] for row in image]
def lighten(image, n):
- width = range(len(image[1]))
+ width = range(len(image[0]))
return [[tuple((row[col][color] + int(n * (255 - row[col][color])))
- for color in range(3)) for col in width] for row in image]
+ for color in range(3)) for col in width] for row in image]
def darken(image, n):
- width = range(len(image[1]))
+ width = range(len(image[0]))
return [[tuple((row[col][color] - int(n * (row[col][color] - 0)))
- for color in range(3)) for col in width] for row in image]
+ for color in range(3)) for col in width] for row in image]
def create_histogram(image):
- red_values = get_values(image, 0)
- green_values = get_values(image, 1)
- blue_values = get_values(image, 2)
+ red_values = get_color_values(image, 0)
+ green_values = get_color_values(image, 1)
+ blue_values = get_color_values(image, 2)
return {'red': red_values, 'green': green_values, 'blue': blue_values}
-def get_values(image, color_index):
- color_values = {x: 0 for x in range(0, 256)}
+def get_color_values(image, color_index):
- for pixels in image:
+ width = range(len(image[0]))
- for pixel in pixels:
+ return Counter(row[col][color_index] for row in image for col in width)
- color_values[pixel[color_index]] += 1
-
- return {p: color_values[p] for p in color_values if color_values[p] != 0}