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

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

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

Резултати

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

Код

def rotate_right(original):
rotated = list(zip(*original[::-1]))
return rotated
def rotate_left(original):
rotated = list(zip(*original))[::-1]
return rotated
def invert(original):
inverted = list()
for pixels in original:
inverted.append(list(map(list, pixels)))
for pixels in inverted:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (255-pixel[index])
invertedInTuple = list()
for pixels in inverted:
invertedInTuple.append(list(map(tuple, pixels)))
return invertedInTuple
def darken(original, coeficient):
darkened = list()
for pixels in original:
darkened.append(list(map(list, pixels)))
for pixels in darkened:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
darkenedInTuple = list()
for pixels in darkened:
darkenInTuple.append(list(map(tuple, pixels)))
return darkenInTuple
def lighten(original, coeficient):
lightened = list()
for pixels in original:
lightened.append(list(map(list, pixels)))
for pixels in lightened:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (
pixel[index] + int(coeficient*(255-pixel[index])))
lightenedInTuple = list()
for pixels in lightened:
lightenedInTuple.append(list(map(tuple, pixels)))
return lightenedInTuple
def create_histogram(original):
histogram = dict()
histogram['red'] = dict()
histogram['green'] = dict()
histogram['blue'] = dict()
for pixels in original:
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
NameError: name 'darkenInTuple' is not defined

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

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

FAILED (errors=2)

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

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

+def rotate_right(original):
+ rotated = list(zip(*original[::-1]))
+ return rotated
+
+
+def rotate_left(original):
+ rotated = list(zip(*original))[::-1]
+ return rotated
+
+
+def invert(original):
+ inverted = list()
+ for pixels in original:
+ inverted.append(list(map(list, pixels)))
+ for pixels in inverted:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (255-pixel[index])
+ invertedInTuple = list()
+ for pixels in inverted:
+ invertedInTuple.append(list(map(tuple, pixels)))
+ return invertedInTuple
+
+
+def darken(original, coeficient):
+ darkened = list()
+ for pixels in original:
+ darken.append(list(map(list, pixels)))
+ for pixels in darkened:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
+ darkenedInTuple = list()
+ for pixels in darkened:
+ darkenInTuple.append(list(map(tuple, pixels)))
+ return darkenInTuple
+
+
+def lighten(original, coeficient):
+ lightened = list()
+ for pixels in original:
+ lightened.append(list(map(list, pixels)))
+ for pixels in lightened:
+ for pixel in pixels:
+ for index in range(0, len(pixel)):
+ pixel[index] = (
+ pixel[index] + int(coeficient*(255-pixel[index])))
+ lightenedInTuple = list()
+ for pixels in lightened:
+ lightenedInTuple.append(list(map(tuple, pixels)))
+ return lightenedInTuple
+
+
+def create_histogram(original):
+ histogram = dict()
+ histogram['red'] = dict()
+ histogram['green'] = dict()
+ histogram['blue'] = dict()
+ for pixels in original:
+ 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

Антон обнови решението на 14.03.2016 16:12 (преди над 5 години)

def rotate_right(original):
rotated = list(zip(*original[::-1]))
return rotated
def rotate_left(original):
rotated = list(zip(*original))[::-1]
return rotated
def invert(original):
inverted = list()
for pixels in original:
inverted.append(list(map(list, pixels)))
for pixels in inverted:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (255-pixel[index])
invertedInTuple = list()
for pixels in inverted:
invertedInTuple.append(list(map(tuple, pixels)))
return invertedInTuple
def darken(original, coeficient):
darkened = list()
for pixels in original:
- darken.append(list(map(list, pixels)))
+ darkened.append(list(map(list, pixels)))
for pixels in darkened:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
darkenedInTuple = list()
for pixels in darkened:
darkenInTuple.append(list(map(tuple, pixels)))
return darkenInTuple
def lighten(original, coeficient):
lightened = list()
for pixels in original:
lightened.append(list(map(list, pixels)))
for pixels in lightened:
for pixel in pixels:
for index in range(0, len(pixel)):
pixel[index] = (
pixel[index] + int(coeficient*(255-pixel[index])))
lightenedInTuple = list()
for pixels in lightened:
lightenedInTuple.append(list(map(tuple, pixels)))
return lightenedInTuple
def create_histogram(original):
histogram = dict()
histogram['red'] = dict()
histogram['green'] = dict()
histogram['blue'] = dict()
for pixels in original:
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