Решение на Работа с картинки от Атанас Василев

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

Към профила на Атанас Василев

Резултати

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

Код

def rotate_left(image):
return list(reversed(list(zip(*image))))
def rotate_right(image):
return (list(zip(*list(reversed(image)))))
def invert(image):
return list(map(invert_help, image))
def invert_help(each):
return list(map(func, each))
def func(pixel):
return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
def lighten(image, coef):
return list([lighten_help(row, coef) for row in image])
def lighten_help(row, coef):
return list([lightenFunc(each, coef) for each in row])
def lightenFunc(pixel, coef):
newRed = int(pixel[0] + coef*(255 - pixel[0]))
newGreen = int(pixel[1] + coef*(255 - pixel[1]))
newBlue = int(pixel[2] + coef*(255 - pixel[2]))
return (newRed, newGreen, newBlue)
def darken(image, coef):
return list([darken_help(row, coef) for row in image])
def darken_help(row, coef):
return list([darkenFunc(each, coef) for each in row])
def darkenFunc(pixel, coef):
newRed = int(pixel[0] + coef*pixel[0])
newGreen = int(pixel[1] + coef*pixel[1])
newBlue = int(pixel[2] + coef*pixel[2])
return (newRed, newGreen, newBlue)
def create_histogram(image):
red = getColour(image, 0)
green = getColour(image, 1)
blue = getColour(image, 2)
return {'red': red, 'green': green, 'blue': blue}
def getColour(image, colour):
result = {}
for each in range(0, 256):
count = countNumber(each, image, colour)
if count > 0:
result[each] = count
return result
def countNumber(el, image, colour):
result = 0
for row in image:
for each in row:
if each[colour] == el:
result = result + 1
return result

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

..FF........
======================================================================
FAIL: test_darken (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: 255 not less than or equal to 1

======================================================================
FAIL: test_darken_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: 100 not less than or equal to 1

----------------------------------------------------------------------
Ran 12 tests in 0.089s

FAILED (failures=2)

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

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

+def rotate_left(image):
+ return list(reversed(list(zip(*image))))
+
+
+def rotate_right(image):
+ return (list(zip(*list(reversed(image)))))
+
+
+def invert(image):
+ return list(map(invert_help, image))
+
+
+def invert_help(each):
+ return list(map(func, each))
+
+
+def func(pixel):
+ return (255 - pixel[0], 255 - pixel[1], 255 - pixel[2])
+
+
+def lighten(image, coef):
+ return list([lighten_help(row, coef) for row in image])
+
+
+def lighten_help(row, coef):
+ return list([lightenFunc(each, coef) for each in row])
+
+
+def lightenFunc(pixel, coef):
+ newRed = int(pixel[0] + coef*(255 - pixel[0]))
+ newGreen = int(pixel[1] + coef*(255 - pixel[1]))
+ newBlue = int(pixel[2] + coef*(255 - pixel[2]))
+ return (newRed, newGreen, newBlue)
+
+
+def darken(image, coef):
+ return list([darken_help(row, coef) for row in image])
+
+
+def darken_help(row, coef):
+ return list([darkenFunc(each, coef) for each in row])
+
+
+def darkenFunc(pixel, coef):
+ newRed = int(pixel[0] + coef*pixel[0])
+ newGreen = int(pixel[1] + coef*pixel[1])
+ newBlue = int(pixel[2] + coef*pixel[2])
+ return (newRed, newGreen, newBlue)
+
+
+def create_histogram(image):
+ red = getColour(image, 0)
+ green = getColour(image, 1)
+ blue = getColour(image, 2)
+ return {'red': red, 'green': green, 'blue': blue}
+
+
+def getColour(image, colour):
+ result = {}
+ for each in range(0, 256):
+ count = countNumber(each, image, colour)
+ if count > 0:
+ result[each] = count
+ return result
+
+
+def countNumber(el, image, colour):
+ result = 0
+ for row in image:
+ for each in row:
+ if each[colour] == el:
+ result = result + 1
+ return result