Решение на Работа с картинки от Илиан Стаменов

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

Към профила на Илиан Стаменов

Резултати

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

Код

def lighten(pic, c):
return [[tuple(pix[i] - int(c * (255 - pix[i])for i in range(3)))
for pix in row] for row in pic]
def darken(pic, c):
return [[tuple(int(pix[i] - c * pix[i])for i in range(3))for pix in row]
for row in pic]
def rotate_right(pic):
return list(zip(*pic[::-1]))
def rotate_left(pic):
return list(zip(*pic))[::-1]
def invert(pic):
return [[tuple(255-pix[i] for i in range(3))for pix in row] for row in pic]
def create_histogram(pic):
res = {"red": {}, "green": {}, "blue": {}}
for row in pic:
for pix in row:
for c, i in (("red", 0), ("green", 1), ("blue", 2)):
res[c][pix[i]] = res[c].get(pix[i], 0) + 1
return res

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

......EE....
======================================================================
ERROR: test_lighten (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
NameError: name 'i' is not defined

======================================================================
ERROR: test_lighten_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
NameError: name 'i' is not defined

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

FAILED (errors=2)

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

Илиан обнови решението на 14.03.2016 00:54 (преди над 5 години)

+def lighten(pic, coef):
+ return [[(pix[0] + int(coef*(255-pix[0])),
+ pix[1] + int(coef*(255-pix[1])),
+ pix[2] + int(coef*(255-pix[2])))for pix in row] for row in pic]
+
+
+def darken(pic, coef):
+ return [[(pix[0] - int(coef*pix[0]),
+ pix[1] - int(coef*pix[1]),
+ pix[2] - int(coef*pix[2]))for pix in row] for row in pic]
+
+
+def rotate_right(pic):
+ return list(zip(*pic[::-1]))
+
+
+def rotate_left(pic):
+ return list(zip(*pic))[::-1]
+
+
+def invert(p):
+ return [[(255-pix[0], 255-pix[1], 255-pix[2])for pix in row] for row in p]
+
+
+def create_histogram(pic):
+ res = {"red": {}, "green": {}, "blue": {}}
+ for row in pic:
+ for pix in row:
+ res["red"][pix[0]] = res["red"].get(pix[0], 0) + 1
+ res["green"][pix[1]] = res["green"].get(pix[1], 0) + 1
+ res["blue"][pix[2]] = res["blue"].get(pix[2], 0) + 1
+ return res

Илиан обнови решението на 14.03.2016 16:18 (преди над 5 години)

-def lighten(pic, coef):
- return [[(pix[0] + int(coef*(255-pix[0])),
- pix[1] + int(coef*(255-pix[1])),
- pix[2] + int(coef*(255-pix[2])))for pix in row] for row in pic]
+def lighten(pic, c):
+ return [[tuple(pix[i] - int(c * (255 - pix[i])for i in range(3)))
+ for pix in row] for row in pic]
-def darken(pic, coef):
- return [[(pix[0] - int(coef*pix[0]),
- pix[1] - int(coef*pix[1]),
- pix[2] - int(coef*pix[2]))for pix in row] for row in pic]
+def darken(pic, c):
+ return [[tuple(int((1 - c) * pix[i])for i in range(3))for pix in row]
+ for row in pic]
def rotate_right(pic):
return list(zip(*pic[::-1]))
def rotate_left(pic):
return list(zip(*pic))[::-1]
-def invert(p):
- return [[(255-pix[0], 255-pix[1], 255-pix[2])for pix in row] for row in p]
+def invert(pic):
+ return [[tuple(255-pix[i] for i in range(3))for pix in row] for row in pic]
def create_histogram(pic):
res = {"red": {}, "green": {}, "blue": {}}
for row in pic:
for pix in row:
- res["red"][pix[0]] = res["red"].get(pix[0], 0) + 1
- res["green"][pix[1]] = res["green"].get(pix[1], 0) + 1
- res["blue"][pix[2]] = res["blue"].get(pix[2], 0) + 1
+ for c, i in (("red", 0), ("green", 1), ("blue", 2)):
+ res[c][pix[i]] = res[c].get(pix[i], 0) + 1
return res

Илиан обнови решението на 14.03.2016 16:25 (преди над 5 години)

def lighten(pic, c):
return [[tuple(pix[i] - int(c * (255 - pix[i])for i in range(3)))
for pix in row] for row in pic]
def darken(pic, c):
- return [[tuple(int((1 - c) * pix[i])for i in range(3))for pix in row]
+ return [[tuple(int(pix[i] - c * pix[i])for i in range(3))for pix in row]
for row in pic]
def rotate_right(pic):
return list(zip(*pic[::-1]))
def rotate_left(pic):
return list(zip(*pic))[::-1]
def invert(pic):
return [[tuple(255-pix[i] for i in range(3))for pix in row] for row in pic]
def create_histogram(pic):
res = {"red": {}, "green": {}, "blue": {}}
for row in pic:
for pix in row:
for c, i in (("red", 0), ("green", 1), ("blue", 2)):
res[c][pix[i]] = res[c].get(pix[i], 0) + 1
return res