timeit

Програмиране с Python

Курс във Факултета по Математика и Информатика към СУ

Решение на Работа с картинки от Ивелина Христова

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

Към профила на Ивелина Христова

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 7 успешни тест(а)
  • 5 неуспешни тест(а)

Код

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def rotate_left(picture):
    rotated_picture = [[] for row in picture]

    for row in picture:
        row_number = 0
        for element in row:
            rotated_picture[row_number].append(element)
            row_number = row_number + 1

    return rotated_picture


def rotate_right(picture):
    rotated_picture = [[] for row in picture]

    for row in reversed(picture):
        row_number = 0
        for element in row:
            rotated_picture[row_number].append(element)
            row_number = row_number + 1

    return rotated_picture


def invert(picture):
    inverted = [[invert_color(color) for color in row] for row in picture]

    return inverted


def invert_color(rgb):
    new_rgb = [255 - value for value in rgb]

    return tuple(new_rgb)


def lighten(picture, *args):
    alpha = args[0]
    lightened = [[lighten_color(color, alpha) for color in row]
    for row in picture]

    return lightened


def lighten_color(rgb, alpha):
    new_rgb = [int(value + alpha*(255 - value)) for value in rgb]

    return tuple(new_rgb)


def darken(picture, *args):
    alpha = args[0]
    darkened = [[darken_color(color, alpha) for color in row]
    for row in picture]

    return darkened


def darken_color(rgb, alpha):
    new_rgb = [int(value - alpha*(value)) for value in rgb]

    return tuple(new_rgb)


def create_histogram(picture):
    histogram = dict()
    rgb = ['red', 'green', 'blue']
    for i in range(len(rgb)):
        histogram[rgb[i]] = {index: len([pixel for row in picture
            for pixel in row if pixel[i] == index]) for index in range(255)}

    return histogram

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

FF......FE.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

======================================================================
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: 5, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0,[5757 chars]: 0}} != {'green': {0: 5, 255: 4}, 'blue': {0: 6, 255: 3}, 'red': {0: 7, 255: 2}}
Diff is 15048 characters long. Set self.maxDiff to None to see it.

======================================================================
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: 4, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0,[5757 chars]: 0}} != {'green': {0: 4, 54: 1, 12: 1, 42: 1, 60: 1, 255: 4}, 'blu[77 chars]: 3}}
Diff is 15122 characters long. Set self.maxDiff to None to see it.

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

First differing element 0:
0
255

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

----------------------------------------------------------------------
Ran 12 tests in 0.148s

FAILED (failures=3, errors=2)

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

Ивелина обнови решението на 13.03.2016 22:29 (преди почти 2 години)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def rotate_left(picture):
    rotated_picture = [[] for row in picture]

    for row in picture:
        row_number = 0
        for element in row:
            rotated_picture[row_number].append(element)
            row_number = row_number + 1

    return rotated_picture


def rotate_right(picture):
    rotated_picture = [[] for row in picture]

    for row in reversed(picture):
        row_number = 0
        for element in row:
            rotated_picture[row_number].append(element)
            row_number = row_number + 1

    return rotated_picture


def invert(picture):
    inverted = [[invert_color(color) for color in row] for row in picture]

    return inverted


def invert_color(rgb):
    new_rgb = [255 - value for value in rgb]

    return tuple(new_rgb)


def lighten(picture, *args):
    alpha = args[0]
    lightened = [[lighten_color(color, alpha) for color in row]
    for row in picture]

    return lightened


def lighten_color(rgb, alpha):
    new_rgb = [int(value + alpha*(255 - value)) for value in rgb]

    return tuple(new_rgb)


def darken(picture, *args):
    alpha = args[0]
    darkened = [[darken_color(color, alpha) for color in row]
    for row in picture]

    return darkened


def darken_color(rgb, alpha):
    new_rgb = [int(value - alpha*(value)) for value in rgb]

    return tuple(new_rgb)


def create_histogram(picture):
    histogram = dict()
    rgb = ['red', 'green', 'blue']
    for i in range(len(rgb)):
        histogram[rgb[i]] = {index: len([pixel for row in picture
            for pixel in row if pixel[i] == index]) for index in range(255)}

    return histogram