Решение на Работа с картинки от Ивелин Тодоров

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

Към профила на Ивелин Тодоров

Резултати

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

Код

from collections import defaultdict
def rotate_left(img):
rotated = zip(*(r[::-1] for r in img))
return list(rotated)
def rotate_right(img):
rotated = zip(*(r for r in img))
return list(rotated)
def invert(img):
inverted = [[tuple([255 - el for el in pix])
for pix in row]
for row in img]
return inverted
def lighten(img, coef):
lightened = [[tuple([int(el + coef*(255 - el)) for el in pix])
for pix in row]
for row in img]
return lightened
def darken(img, coef):
darkened = [[tuple([int(el - coef*(el - 0)) for el in pix])
for pix in row]
for row in img]
return darkened
def create_histogram(img):
histogram = {}
temp = defaultdict(int)
keys = ('red', 'green', 'blue')
for ind, key in enumerate(keys):
for row in img:
for pix in row:
temp[pix[ind]] += 1
histogram[key] = temp
temp = defaultdict(int)
return histogram

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

..........FF
======================================================================
FAIL: test_rotate_right (test.TestImages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Tuples differ: (0, 255, 0) != (0, 0, 255)

First differing element 1:
255
0

- (0, 255, 0)
+ (0, 0, 255)

======================================================================
FAIL: test_rotate_right_rectangle (test.TestImages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Tuples differ: (0, 255, 1) != (100, 0, 255)

First differing element 0:
0
100

- (0, 255, 1)
+ (100, 0, 255)

----------------------------------------------------------------------
Ran 12 tests in 0.092s

FAILED (failures=2)

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

Ивелин обнови решението на 13.03.2016 20:56 (преди над 5 години)

+from collections import defaultdict
+
+
+def rotate_left(img):
+ rotated = zip(*(r[::-1] for r in img))
+ return list(rotated)
+
+
+def rotate_right(img):
+ rotated = zip(*(r for r in img))
+ return list(rotated)
+
+
+def invert(img):
+ inverted = [[tuple([255 - el for el in pix])
+ for pix in row]
+ for row in img]
+
+ return inverted
+
+
+def lighten(img, coef):
+ lightened = [[tuple([int(el + coef*(255 - el)) for el in pix])
+ for pix in row]
+ for row in img]
+
+ return lightened
+
+
+def darken(img, coef):
+ darkened = [[tuple([int(el - coef*(el - 0)) for el in pix])
+ for pix in row]
+ for row in img]
+
+ return darkened
+
+
+def create_histogram(img):
+ histogram = {}
+ temp = defaultdict(int)
+ keys = ('red', 'green', 'blue')
+ for ind, key in enumerate(keys):
+ for row in img:
+ for pix in row:
+ temp[pix[ind]] += 1
+ histogram[key] = temp
+ temp = defaultdict(int)
+ return histogram