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

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

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

Резултати

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

Код

def rotate_left(image):
rotated_image = []
for row in range(len(image)):
rotated_image.append([])
for col in range(len(image[row])):
rotated_image[row].append(image[col][len(image) - row - 1])
return rotated_image
def rotate_right(image):
rotated_image = []
for row in range(len(image)):
rotated_image.append([])
for col in range(len(image[row])):
rotated_image[row].append(image[len(image) - col - 1][row])
return rotated_image
def invert(image):
inverted_image = []
for row in range(len(image)):
inverted_image.append([])
for col in range(len(image[row])):
pixel = list(image[row][col])
for i in range(len(image[row][col])):
pixel[i] = 255 - pixel[i]
inverted_image[row].append(tuple(pixel))
return inverted_image
def lighten(image, coeff):
lightened_image = []
for row in range(len(image)):
lightened_image.append([])
for col in range(len(image[row])):
pixel = list(image[row][col])
for i in range(len(image[row][col])):
pixel[i] = int(pixel[i] + coeff * (255 - pixel[i]))
lightened_image[row].append(tuple(pixel))
return lightened_image
def darken(image, coeff):
darkened_image = []
for row in range(len(image)):
darkened_image.append([])
for col in range(len(image[row])):
pixel = list(image[row][col])
for i in range(len(image[row][col])):
pixel[i] = int(pixel[i] - coeff * (pixel[i] - 0))
darkened_image[row].append(tuple(pixel))
return darkened_image
def create_histogram(image):
rgb_colors = ['red', 'green', 'blue']
histogram = {color: {} for color in rgb_colors}
for row in range(len(image)):
for red, green, blue in image[row]:
if red in histogram[rgb_colors[0]]:
histogram[rgb_colors[0]][red] += 1
else:
histogram[rgb_colors[0]][red] = 1
if green in histogram[rgb_colors[1]]:
histogram[rgb_colors[1]][green] += 1
else:
histogram[rgb_colors[1]][green] = 1
if blue in histogram[rgb_colors[2]]:
histogram[rgb_colors[2]][blue] += 1
else:
histogram[rgb_colors[2]][blue] = 1
return histogram

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

.........E.E
======================================================================
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

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

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

FAILED (errors=2)

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

Марина обнови решението на 14.03.2016 01:06 (преди над 5 години)

+def rotate_left(image):
+ rotated_image = []
+ for row in range(len(image)):
+ rotated_image.append([])
+ for col in range(len(image[row])):
+ rotated_image[row].append(image[col][len(image) - row - 1])
+ return rotated_image
+
+
+def rotate_right(image):
+ rotated_image = []
+ for row in range(len(image)):
+ rotated_image.append([])
+ for col in range(len(image[row])):
+ rotated_image[row].append(image[len(image) - col - 1][row])
+ return rotated_image
+
+
+def invert(image):
+ inverted_image = []
+ for row in range(len(image)):
+ inverted_image.append([])
+ for col in range(len(image[row])):
+ pixel = list(image[row][col])
+ for i in range(len(image[row][col])):
+ pixel[i] = 255 - pixel[i]
+ inverted_image[row].append(tuple(pixel))
+ return inverted_image
+
+
+def lighten(image, coeff):
+ lightened_image = []
+ for row in range(len(image)):
+ lightened_image.append([])
+ for col in range(len(image[row])):
+ pixel = list(image[row][col])
+ for i in range(len(image[row][col])):
+ pixel[i] = int(pixel[i] + coeff * (255 - pixel[i]))
+ lightened_image[row].append(tuple(pixel))
+ return lightened_image
+
+
+def darken(image, coeff):
+ darkened_image = []
+ for row in range(len(image)):
+ darkened_image.append([])
+ for col in range(len(image[row])):
+ pixel = list(image[row][col])
+ for i in range(len(image[row][col])):
+ pixel[i] = int(pixel[i] - coeff * (pixel[i] - 0))
+ darkened_image[row].append(tuple(pixel))
+ return darkened_image
+
+
+def create_histogram(image):
+ rgb_colors = ['red', 'green', 'blue']
+ histogram = {color: {} for color in rgb_colors}
+
+ for row in range(len(image)):
+ for red, green, blue in image[row]:
+ if red in histogram[rgb_colors[0]]:
+ histogram[rgb_colors[0]][red] += 1
+ else:
+ histogram[rgb_colors[0]][red] = 1
+
+ if green in histogram[rgb_colors[1]]:
+ histogram[rgb_colors[1]][green] += 1
+ else:
+ histogram[rgb_colors[1]][green] = 1
+
+ if blue in histogram[rgb_colors[2]]:
+ histogram[rgb_colors[2]][blue] += 1
+ else:
+ histogram[rgb_colors[2]][blue] = 1
+ return histogram