Решение на Работа с картинки от Хризантема Станчева

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

Към профила на Хризантема Станчева

Резултати

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

Код

def transpose(matrix):
res = [list(i) for i in zip(*matrix)]
return res
def rotate_left(image):
transposed_image = transpose(image)
new_image = transposed_image[::-1]
return new_image
def rotate_right(image):
reversed_image = image[::-1]
new_image = transpose(reversed_image)
return new_image
def invert_pixel(pixel):
return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
def invert_row(row):
return list(map(invert_pixel, row))
def invert(image):
return list(map(invert_row, image))
def lighten_pixel(pixel, number):
red = pixel[0] + number * (255 - pixel[0])
green = pixel[1] + number * (255 - pixel[1])
blue = pixel[2] + number * (255 - pixel[2])
return (int(red), int(green), int(blue))
def lighten(image, number):
new_image = []
for row in image:
current_row = list(map(lambda x: lighten_pixel(x, number), row))
new_image.append(current_row)
return new_image
def darken_pixel(pixel, number):
red = pixel[0] - number * pixel[0]
green = pixel[1] - number * pixel[1]
blue = pixel[2] - number * pixel[2]
return (int(red), int(green), int(blue))
def darken(image, number):
new_image = []
for row in image:
current_row = list(map(lambda x: darken_pixel(x, number), row))
new_image.append(current_row)
return new_image
def create_histogram(image):
histogram = {'red': {}, 'green': {}, 'blue': {}}
for row in image:
for (r, g, b) in row:
if r in histogram['red']:
histogram['red'][r] += 1
else:
histogram['red'][r] = 1
if g in histogram['green']:
histogram['green'][g] += 1
else:
histogram['green'][g] = 1
if b in histogram['blue']:
histogram['blue'][b] += 1
else:
histogram['blue'][b] = 1
return histogram

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

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

OK

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

Хризантема обнови решението на 13.03.2016 23:09 (преди над 5 години)

+def transpose(matrix):
+ res = [list(i) for i in zip(*matrix)]
+ return res
+
+
+def rotate_left(image):
+ transposed_image = transpose(image)
+ new_image = transposed_image[::-1]
+ return new_image
+
+
+def rotate_right(image):
+ reversed_image = image[::-1]
+ new_image = transpose(reversed_image)
+ return new_image
+
+
+def invert_pixel(pixel):
+ return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
+
+
+def invert_row(row):
+ return list(map(invert_pixel, row))
+
+
+def invert(image):
+ return list(map(invert_row, image))
+
+
+def lighten_pixel(pixel, number):
+ red = pixel[0] + number * (255 - pixel[0])
+ green = pixel[1] + number * (255 - pixel[1])
+ blue = pixel[2] + number * (255 - pixel[2])
+ return (int(red), int(green), int(blue))
+
+
+def lighten(image, number):
+ new_image = []
+ for row in image:
+ current_row = list(map(lambda x: lighten_pixel(x, number), row))
+ new_image.append(current_row)
+ return new_image
+
+
+def darken_pixel(pixel, number):
+ red = pixel[0] - number * pixel[0]
+ green = pixel[1] - number * pixel[1]
+ blue = pixel[2] - number * pixel[2]
+ return (int(red), int(green), int(blue))
+
+
+def darken(image, number):
+ new_image = []
+ for row in image:
+ current_row = list(map(lambda x: darken_pixel(x, number), row))
+ new_image.append(current_row)
+ return new_image
+
+
+def create_histogram(image):
+ histogram = {'red': {}, 'green': {}, 'blue': {}}
+ for row in image:
+ for (r, g, b) in row:
+ if r in histogram['red']:
+ histogram['red'][r] += 1
+ else:
+ histogram['red'][r] = 1
+ if g in histogram['green']:
+ histogram['green'][g] += 1
+ else:
+ histogram['green'][g] = 1
+ if b in histogram['blue']:
+ histogram['blue'][b] += 1
+ else:
+ histogram['blue'][b] = 1
+ return histogram