Решение на Работа с картинки от Кристина Христакиева

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

Към профила на Кристина Христакиева

Резултати

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

Код

import collections
MAX_COLOR_VALUE = 255
def create_histogram(image):
result = {}
result['red'] = collections.defaultdict(int)
result['green'] = collections.defaultdict(int)
result['blue'] = collections.defaultdict(int)
for row in image:
for (red, green, blue) in row:
result['red'][red] += 1
result['green'][green] += 1
result['blue'][blue] += 1
return result
def rotate_left(image):
columns = len(image[0])
rows = len(image)
result = [[image[row][columns - col - 1]
for row in range(rows)] for col in range(columns)]
return result
def rotate_right(image):
columns = len(image[0])
rows = len(image)
result = [[image[rows - row - 1][col]
for row in range(rows)] for col in range(columns)]
return result
def lighten_pixel(pixel, coef):
lightened_pixel = tuple(
[int(color + coef * (MAX_COLOR_VALUE - color)) for color in pixel])
return lightened_pixel
def lighten(image, coef):
result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]
return result
def darken_pixel(pixel, coef):
darkened_pixel = tuple([int(color - (coef * color)) for color in pixel])
return darkened_pixel
def darken(image, coef):
result = [[darken_pixel(item, coef) for item in row] for row in image]
return result
def invert_pixel(pixel):
inverted_pixel = tuple([MAX_COLOR_VALUE - color for color in pixel])
return inverted_pixel
def invert(image):
result = [[invert_pixel(pixel) for pixel in row] for row in image]
return result

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.084s

OK

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

Кристина обнови решението на 13.03.2016 22:45 (преди над 5 години)

+import collections
+
+MAX_COLOR_VALUE = 255
+
+
+def create_histogram(image):
+
+ result = {}
+
+ result['red'] = collections.defaultdict(int)
+ result['green'] = collections.defaultdict(int)
+ result['blue'] = collections.defaultdict(int)
+
+ for row in image:
+ for (red, green, blue) in row:
+ result['red'][red] += 1
+ result['green'][green] += 1
+ result['blue'][blue] += 1
+
+ return result
+
+
+red, green, blue = 0, 1, 2
+
+
+def rotate_left(image):
+
+ columns = len(image[0])
+ rows = len(image)
+
+ result = [[image[row][columns - i - 1]
+ for row in range(rows)] for i in range(columns)]
+
+ return result
+
+
+def rotate_right(image):
+
+ columns = len(image[0])
+ rows = len(image)
+
+ result = [[image[rows - row - 1][col]
+ for row in range(rows)] for col in range(columns)]
+
+ return result
+
+
+def lighten_pixel(pixel, coef):
+
+ lightened_pixel = tuple(
+ [int(colour + coef * (MAX_COLOR_VALUE - colour)) for colour in pixel])
+
+ return lightened_pixel
+
+
+def lighten(image, coef):
+
+ result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]
+
+ return result
+
+
+def darken_pixel(pixel, coef):
+
+ darkened_pixel = tuple([int(colour - coef * (colour - 0))
+ for colour in pixel])
+
+ return darkened_pixel
+
+
+def darken(image, coef):
+
+ result = [[darken_pixel(item, coef) for item in row] for row in image]
+
+ return result
+
+
+def invert_pixel(pixel):
+
+ inverted_pixel = tuple([MAX_COLOR_VALUE - colour for colour in pixel])
+
+ return inverted_pixel
+
+
+def invert(image):
+
+ result = [[invert_pixel(pixel) for pixel in row] for row in image]
+
+ return result

Кристина обнови решението на 13.03.2016 23:00 (преди над 5 години)

import collections
MAX_COLOR_VALUE = 255
def create_histogram(image):
result = {}
result['red'] = collections.defaultdict(int)
result['green'] = collections.defaultdict(int)
result['blue'] = collections.defaultdict(int)
for row in image:
for (red, green, blue) in row:
result['red'][red] += 1
result['green'][green] += 1
result['blue'][blue] += 1
return result
red, green, blue = 0, 1, 2
def rotate_left(image):
columns = len(image[0])
rows = len(image)
- result = [[image[row][columns - i - 1]
- for row in range(rows)] for i in range(columns)]
+ result = [[image[row][columns - col - 1]
+ for row in range(rows)] for col in range(columns)]
return result
def rotate_right(image):
columns = len(image[0])
rows = len(image)
result = [[image[rows - row - 1][col]
for row in range(rows)] for col in range(columns)]
return result
def lighten_pixel(pixel, coef):
lightened_pixel = tuple(
[int(colour + coef * (MAX_COLOR_VALUE - colour)) for colour in pixel])
return lightened_pixel
def lighten(image, coef):
result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]
return result
def darken_pixel(pixel, coef):
darkened_pixel = tuple([int(colour - coef * (colour - 0))
for colour in pixel])
return darkened_pixel
def darken(image, coef):
result = [[darken_pixel(item, coef) for item in row] for row in image]
return result
def invert_pixel(pixel):
inverted_pixel = tuple([MAX_COLOR_VALUE - colour for colour in pixel])
return inverted_pixel
def invert(image):
result = [[invert_pixel(pixel) for pixel in row] for row in image]
return result

Кристина обнови решението на 14.03.2016 14:30 (преди над 5 години)

import collections
MAX_COLOR_VALUE = 255
def create_histogram(image):
result = {}
result['red'] = collections.defaultdict(int)
result['green'] = collections.defaultdict(int)
result['blue'] = collections.defaultdict(int)
for row in image:
for (red, green, blue) in row:
result['red'][red] += 1
result['green'][green] += 1
result['blue'][blue] += 1
return result
-red, green, blue = 0, 1, 2
-
-
def rotate_left(image):
columns = len(image[0])
rows = len(image)
result = [[image[row][columns - col - 1]
for row in range(rows)] for col in range(columns)]
return result
def rotate_right(image):
columns = len(image[0])
rows = len(image)
result = [[image[rows - row - 1][col]
for row in range(rows)] for col in range(columns)]
return result
def lighten_pixel(pixel, coef):
lightened_pixel = tuple(
- [int(colour + coef * (MAX_COLOR_VALUE - colour)) for colour in pixel])
+ [int(color + coef * (MAX_COLOR_VALUE - color)) for color in pixel])
return lightened_pixel
def lighten(image, coef):
result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]
return result
def darken_pixel(pixel, coef):
- darkened_pixel = tuple([int(colour - coef * (colour - 0))
- for colour in pixel])
+ darkened_pixel = tuple([int(color - (coef * color)) for color in pixel])
return darkened_pixel
def darken(image, coef):
result = [[darken_pixel(item, coef) for item in row] for row in image]
return result
def invert_pixel(pixel):
- inverted_pixel = tuple([MAX_COLOR_VALUE - colour for colour in pixel])
+ inverted_pixel = tuple([MAX_COLOR_VALUE - color for color in pixel])
return inverted_pixel
def invert(image):
result = [[invert_pixel(pixel) for pixel in row] for row in image]
return result