Решение на Работа с картинки от Мюмюн Исмаил

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

Към профила на Мюмюн Исмаил

Резултати

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

Код

def lighten(image, coef):
result_image = []
current_pixel_row = []
max_value = 255
for row in image:
for r, g, b in row:
r_value = r + int(coef * (max_value - r))
g_value = g + int(coef * (max_value - g))
b_value = b + int(coef * (max_value - b))
current_pixel_row.append((r_value, g_value, b_value))
result_image.append(current_pixel_row[:])
current_pixel_row[:] = []
return result_image
def rotate_right(image):
return [list(i) for i in list(zip(*image[::-1]))]
def rotate_left(image):
return [list(i) for i in list(zip(*image))[::-1]]
def darken(image, coef):
result_image = []
current_pixel_row = []
for row in image:
for r, g, b in row:
r_value = r - int(coef * r)
g_value = g - int(coef * g)
b_value = b - int(coef * b)
current_pixel_row.append((r_value, g_value, b_value))
result_image.append(current_pixel_row[:])
current_pixel_row[:] = []
return result_image
def invert(image):
result_image = []
current_pixel_row = []
max_value = 255
for pixel_row in image:
for r, g, b in pixel_row:
r_inverse = max_value - r
g_inverse = max_value - g
b_inverse = max_value - b
current_pixel_row.append((r_inverse, g_inverse, b_inverse))
result_image.append(current_pixel_row[:])
current_pixel_row[:] = []
return result_image
def create_histogram(image):
histogram_dict = dict.fromkeys(['red', 'green', 'blue'], {})
for row in image:
for r, g, b in row:
add_elements(histogram_dict, 'red', r)
add_elements(histogram_dict, 'green', g)
add_elements(histogram_dict, 'blue', b)
return histogram_dict
def add_elements(dictionary, colour, colour_code):
if colour_code in dictionary[colour]:
dictionary[colour][colour_code] += 1
else:
dictionary[colour][colour_code] = 1

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

FF..........
======================================================================
FAIL: test_create_histogram (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: {'green': {0: 18, 255: 9}, 'red': {0: 18, 255: 9}, 'blue': {0: 18, 255: 9}} != {'green': {0: 5, 255: 4}, 'red': {0: 7, 255: 2}, 'blue': {0: 6, 255: 3}}
- {'blue': {0: 18, 255: 9}, 'green': {0: 18, 255: 9}, 'red': {0: 18, 255: 9}}
?              ^^       ^                ^^       ^              ^^       ^

+ {'blue': {0: 6, 255: 3}, 'green': {0: 5, 255: 4}, 'red': {0: 7, 255: 2}}
?              ^       ^                ^       ^              ^       ^


======================================================================
FAIL: test_create_histogram_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: {'green': {0: 14, 1: 3, 60: 1, 100: 1, 54: 1, 72: 1, 4:[204 chars] 11}} != {'green': {0: 4, 54: 1, 12: 1, 42: 1, 60: 1, 255: 4}, '[80 chars]: 4}}
Diff is 782 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 12 tests in 0.091s

FAILED (failures=2)

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

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

+def lighten(image, coef):
+ result_image = []
+ current_pixel_row = []
+ max_value = 255
+ for row in image:
+ for r, g, b in row:
+ r_value = r + int(coef * (max_value - r))
+ g_value = g + int(coef * (max_value - g))
+ b_value = b + int(coef * (max_value - b))
+ current_pixel_row.append((r_value, g_value, b_value))
+ result_image.append(current_pixel_row[:])
+ current_pixel_row[:] = []
+ return result_image
+
+
+def rotate_right(image):
+ return [list(i) for i in list(zip(*image[::-1]))]
+
+
+def rotate_left(image):
+ return [list(i) for i in list(zip(*image))[::-1]]
+
+
+def darken(image, coef):
+ result_image = []
+ current_pixel_row = []
+ for row in image:
+ for r, g, b in row:
+ r_value = r - int(coef * r)
+ g_value = g - int(coef * g)
+ b_value = b - int(coef * b)
+ current_pixel_row.append((r_value, g_value, b_value))
+ result_image.append(current_pixel_row[:])
+ current_pixel_row[:] = []
+ return result_image
+
+
+def invert(image):
+ result_image = []
+ current_pixel_row = []
+ max_value = 255
+ for pixel_row in image:
+ for r, g, b in pixel_row:
+ r_inverse = max_value - r
+ g_inverse = max_value - g
+ b_inverse = max_value - b
+ current_pixel_row.append((r_inverse, g_inverse, b_inverse))
+ result_image.append(current_pixel_row[:])
+ current_pixel_row[:] = []
+ return result_image
+
+
+def create_histogram(image):
+ histogram_dict = dict.fromkeys(['red', 'green', 'blue'], {})
+ for row in image:
+ for r, g, b in row:
+ add_elements(histogram_dict, 'red', r)
+ add_elements(histogram_dict, 'green', g)
+ add_elements(histogram_dict, 'blue', b)
+ return histogram_dict
+
+
+def add_elements(dictionary, colour, colour_code):
+ if colour_code in dictionary[colour]:
+ dictionary[colour][colour_code] += 1
+ else:
+ dictionary[colour][colour_code] = 1