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

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

Към профила на Галин Ангелов

Резултати

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

Код

def rotate_left(image):
newImage = []
k = 0
p = 1
for row in range(0, len(image)):
line = []
for col in range(0, len(image[row])):
el = image[k][len(image[row])-p]
line.append(el)
k += 1
p += 1
k = 0
newImage.append(line)
return newImage
def rotate_right(image):
newImage = []
k = 0
p = 1
for row in range(0, len(image)):
line = []
for col in range(0, len(image[row])):
el = image[len(image)-p][k]
line.append(el)
k += 1
p += 1
k = 0
newImage.append(line)
return newImage
def invert(image):
newImage = []
for row in range(0, len(image)):
line = []
for col in range(0, len(image[row])):
innerTuple = list(image[row][col])
for index in range(len(innerTuple)):
innerTuple[index] = 255 - innerTuple[index]
line.append(tuple(innerTuple))
newImage.append(line)
return newImage
def lighten(image, value):
newImage = []
for row in range(0, len(image)):
line = []
for col in range(0, len(image[row])):
innerTuple = list(image[row][col])
for index in range(len(innerTuple)):
element = innerTuple[index]
innerTuple[index] = int(element + value*(255 - element))
line.append(tuple(innerTuple))
newImage.append(line)
return newImage
def darken(image, value):
newImage = []
for row in range(0, len(image)):
line = []
for col in range(0, len(image[row])):
innerTuple = list(image[row][col])
for index in range(len(innerTuple)):
element = innerTuple[index]
innerTuple[index] = int(element - value*(element - 0))
line.append(tuple(innerTuple))
newImage.append(line)
return newImage
def create_histogram(image):
histogram = {}
red = {}
green = {}
blue = {}
for row in range(0, len(image)):
for col in range(0, len(image[row])):
for index in range(len(image[row][col])):
element = image[row][col][index]
if index is 0:
if element not in red:
red[element] = 1
else:
red[element] += 1
histogram['red'] = red
if index is 1:
if element not in green:
green[element] = 1
else:
green[element] += 1
histogram['green'] = green
if index is 2:
if element not in blue:
blue[element] = 1
else:
blue[element] += 1
histogram['blue'] = blue
return histogram

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

.........EFF
======================================================================
ERROR: test_rotate_left_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
IndexError: list index out of range

======================================================================
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: (255, 0, 0) != (0, 255, 0)

First differing element 0:
255
0

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

======================================================================
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: (255, 0, 4) != (72, 255, 0)

First differing element 0:
255
72

- (255, 0, 4)
+ (72, 255, 0)

----------------------------------------------------------------------
Ran 12 tests in 0.101s

FAILED (failures=2, errors=1)

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

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

+def rotate_left(image):
+ newImage = []
+ k = 0
+ p = 1
+ for row in range(0, len(image)):
+ line = []
+ for col in range(0, len(image[row])):
+ el = image[k][len(image[row])-p]
+ line.append(el)
+ k += 1
+ p += 1
+ k = 0
+ newImage.append(line)
+ return newImage
+
+
+def rotate_right(image):
+ newImage = []
+ k = 0
+ p = 1
+ for row in range(0, len(image)):
+ line = []
+ for col in range(0, len(image[row])):
+ el = image[len(image)-p][k]
+ line.append(el)
+ k += 1
+ p += 1
+ k = 0
+ newImage.append(line)
+ return newImage
+
+
+def invert(image):
+ newImage = []
+ for row in range(0, len(image)):
+ line = []
+ for col in range(0, len(image[row])):
+ innerTuple = list(image[row][col])
+ for index in range(len(innerTuple)):
+ innerTuple[index] = 255 - innerTuple[index]
+ line.append(tuple(innerTuple))
+ newImage.append(line)
+ return newImage
+
+
+def lighten(image, value):
+ newImage = []
+ for row in range(0, len(image)):
+ line = []
+ for col in range(0, len(image[row])):
+ innerTuple = list(image[row][col])
+ for index in range(len(innerTuple)):
+ element = innerTuple[index]
+ innerTuple[index] = int(element + value*(255 - element))
+ line.append(tuple(innerTuple))
+ newImage.append(line)
+ return newImage
+
+
+def darken(image, value):
+ newImage = []
+ for row in range(0, len(image)):
+ line = []
+ for col in range(0, len(image[row])):
+ innerTuple = list(image[row][col])
+ for index in range(len(innerTuple)):
+ element = innerTuple[index]
+ innerTuple[index] = int(element - value*(element - 0))
+ line.append(tuple(innerTuple))
+ newImage.append(line)
+ return newImage
+
+
+def create_histogram(image):
+ histogram = {}
+ red = {}
+ green = {}
+ blue = {}
+ for row in range(0, len(image)):
+ for col in range(0, len(image[row])):
+
+ for index in range(len(image[row][col])):
+ element = image[row][col][index]
+ if index is 0:
+ if element not in red:
+ red[element] = 1
+ else:
+ red[element] += 1
+ histogram['red'] = red
+ if index is 1:
+ if element not in green:
+ green[element] = 1
+ else:
+ green[element] += 1
+ histogram['green'] = green
+ if index is 2:
+ if element not in blue:
+ blue[element] = 1
+ else:
+ blue[element] += 1
+ histogram['blue'] = blue
+ return histogram