Решение на Работа с картинки от Иван Вичев

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

Към профила на Иван Вичев

Резултати

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

Код

def rotate_left(M):
rotated = list(zip(*M))[::-1]
return rotated
def rotate_right(M):
rotated = list(zip(*M[::-1]))
return rotated
def invert(M):
invertedI = []
for pixels in M:
invertedI.append(list(map(list, pixels)))
for pixels in invertedI:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (255-pixel[index])
invertedII = []
for pixels in invertedI:
invertedII.append(list(map(tuple, pixels)))
return invertedII
def lighten(M, coeficient):
lightenI = []
for pixels in M:
lightenI.append(list(map(list, pixels)))
for pixels in lightenI:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (
pixel[index] + int(coeficient*(255-pixel[index])))
lightenII = []
for pixels in lightenI:
lightenII.append(list(map(tuple, pixels)))
return lightenII
def darken(M, coeficient):
darkenI = []
for pixels in M:
darken.append(list(map(list, pixels)))
for pixels in darken:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
darkenII = []
for pixels in darkenI:
darkenII.append(list(map(tuple, pixels)))
return darkenII
def create_histogram(M):
histogram = {'red': {}, 'green': {}, 'blue': {}, }
for pixels in M:
for pixel in pixels:
for index in range(0, len(pixel)):
if(index == 0):
if(pixel[index] in histogram['red']):
histogram['red'][pixel[index]] = 1 + \
histogram['red'][pixel[index]]
else:
histogram['red'][pixel[index]] = 1
if(index == 1):
if(pixel[index] in histogram['green']):
histogram['green'][pixel[index]] = 1 + \
histogram['green'][pixel[index]]
else:
histogram['green'][pixel[index]] = 1
if(index == 2):
if(pixel[index] in histogram['blue']):
histogram['blue'][pixel[index]] = 1 + \
histogram['blue'][pixel[index]]
else:
histogram['blue'][pixel[index]] = 1
return histogram

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

..EE........
======================================================================
ERROR: 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
AttributeError: 'function' object has no attribute 'append'

======================================================================
ERROR: 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
AttributeError: 'function' object has no attribute 'append'

----------------------------------------------------------------------
Ran 12 tests in 0.085s

FAILED (errors=2)

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

Иван обнови решението на 13.03.2016 22:57 (преди над 5 години)

+def rotate_left(M):
+ rotated = list(zip(*M))[::-1]
+ return rotated
+
+
+def rotate_right(M):
+ rotated = list(zip(*M[::-1]))
+ return rotated
+
+
+def invert(M):
+ invertedI = []
+ for pixels in M:
+ invertedI.append(list(map(list, pixels)))
+ for pixels in invertedI:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (255-pixel[index])
+ invertedII = []
+ for pixels in invertedI:
+ invertedII.append(list(map(tuple, pixels)))
+ return invertedII
+
+
+def lighten(M, coeficient):
+ lightenI = []
+ for pixels in M:
+ lightenI.append(list(map(list, pixels)))
+ for pixels in lightenI:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (
+ pixel[index] + int(coeficient*(255-pixel[index])))
+ lightenII = []
+ for pixels in lightenI:
+ lightenII.append(list(map(tuple, pixels)))
+ return lightenII
+
+
+def darken(M, coeficient):
+ darkenI = []
+ for pixels in M:
+ darken.append(list(map(list, pixels)))
+ for pixels in darken:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
+ darkenII = []
+ for pixels in darkenI:
+ darkenII.append(list(map(tuple, pixels)))
+ return darkenII

Иван обнови решението на 14.03.2016 15:10 (преди над 5 години)

def rotate_left(M):
rotated = list(zip(*M))[::-1]
return rotated
def rotate_right(M):
rotated = list(zip(*M[::-1]))
return rotated
def invert(M):
invertedI = []
for pixels in M:
invertedI.append(list(map(list, pixels)))
for pixels in invertedI:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (255-pixel[index])
invertedII = []
for pixels in invertedI:
invertedII.append(list(map(tuple, pixels)))
return invertedII
def lighten(M, coeficient):
lightenI = []
for pixels in M:
lightenI.append(list(map(list, pixels)))
for pixels in lightenI:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (
pixel[index] + int(coeficient*(255-pixel[index])))
lightenII = []
for pixels in lightenI:
lightenII.append(list(map(tuple, pixels)))
return lightenII
def darken(M, coeficient):
darkenI = []
for pixels in M:
darken.append(list(map(list, pixels)))
for pixels in darken:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
darkenII = []
for pixels in darkenI:
darkenII.append(list(map(tuple, pixels)))
- return darkenII
+ return darkenII
+
+
+def create_histogram(M):
+ histogram = {'red': {}, 'green': {}, 'blue': {}, }
+ for pixels in M:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ if(index == 0):
+ if(pixel[index] in histogram['red']):
+ histogram['red'][pixel[index]] = 1 + \
+ histogram['red'][pixel[index]]
+ else:
+ histogram['red'][pixel[index]] = 1
+ if(index == 1):
+ if(pixel[index] in histogram['green']):
+ histogram['green'][pixel[index]] = 1 + \
+ histogram['green'][pixel[index]]
+ else:
+ histogram['green'][pixel[index]] = 1
+ if(index == 2):
+ if(pixel[index] in histogram['blue']):
+ histogram['blue'][pixel[index]] = 1 + \
+ histogram['blue'][pixel[index]]
+ else:
+ histogram['blue'][pixel[index]] = 1
+ return histogram