timeit

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

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

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

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

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

Резултати

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

Код

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
74
75
76
77
78
79
80
81
82
83
84
85
import collections

MAX_COLOR_VALUE = 255


def create_histogram(image):

    result = {}

    result['red'] = collections.defaultdict(int)
    result['green'] = collections.defaultdict(int)
    result['blue'] = collections.defaultdict(int)

    for row in image:
        for (red, green, blue) in row:
            result['red'][red] += 1
            result['green'][green] += 1
            result['blue'][blue] += 1

    return result


def rotate_left(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[row][columns - col - 1]
               for row in range(rows)] for col in range(columns)]

    return result


def rotate_right(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[rows - row - 1][col]
               for row in range(rows)] for col in range(columns)]

    return result


def lighten_pixel(pixel, coef):

    lightened_pixel = tuple(
        [int(color + coef * (MAX_COLOR_VALUE - color)) for color in pixel])

    return lightened_pixel


def lighten(image, coef):

    result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]

    return result


def darken_pixel(pixel, coef):

    darkened_pixel = tuple([int(color - (coef * color)) for color in pixel])

    return darkened_pixel


def darken(image, coef):

    result = [[darken_pixel(item, coef) for item in row] for row in image]

    return result


def invert_pixel(pixel):

    inverted_pixel = tuple([MAX_COLOR_VALUE - color for color in pixel])

    return inverted_pixel


def invert(image):

    result = [[invert_pixel(pixel) for pixel in row] for row in image]

    return result

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.084s

OK

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

Кристина обнови решението на 13.03.2016 22:45 (преди почти 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import collections

MAX_COLOR_VALUE = 255


def create_histogram(image):

    result = {}

    result['red'] = collections.defaultdict(int)
    result['green'] = collections.defaultdict(int)
    result['blue'] = collections.defaultdict(int)

    for row in image:
        for (red, green, blue) in row:
            result['red'][red] += 1
            result['green'][green] += 1
            result['blue'][blue] += 1

    return result


red, green, blue = 0, 1, 2


def rotate_left(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[row][columns - i - 1]
               for row in range(rows)] for i in range(columns)]

    return result


def rotate_right(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[rows - row - 1][col]
               for row in range(rows)] for col in range(columns)]

    return result


def lighten_pixel(pixel, coef):

    lightened_pixel = tuple(
        [int(colour + coef * (MAX_COLOR_VALUE - colour)) for colour in pixel])

    return lightened_pixel


def lighten(image, coef):

    result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]

    return result


def darken_pixel(pixel, coef):

    darkened_pixel = tuple([int(colour - coef * (colour - 0))
                           for colour in pixel])

    return darkened_pixel


def darken(image, coef):

    result = [[darken_pixel(item, coef) for item in row] for row in image]

    return result


def invert_pixel(pixel):

    inverted_pixel = tuple([MAX_COLOR_VALUE - colour for colour in pixel])

    return inverted_pixel


def invert(image):

    result = [[invert_pixel(pixel) for pixel in row] for row in image]

    return result

Кристина обнови решението на 13.03.2016 23:00 (преди почти 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import collections

MAX_COLOR_VALUE = 255


def create_histogram(image):

    result = {}

    result['red'] = collections.defaultdict(int)
    result['green'] = collections.defaultdict(int)
    result['blue'] = collections.defaultdict(int)

    for row in image:
        for (red, green, blue) in row:
            result['red'][red] += 1
            result['green'][green] += 1
            result['blue'][blue] += 1

    return result


red, green, blue = 0, 1, 2


def rotate_left(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[row][columns - col - 1]
               for row in range(rows)] for col in range(columns)]

    return result


def rotate_right(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[rows - row - 1][col]
               for row in range(rows)] for col in range(columns)]

    return result


def lighten_pixel(pixel, coef):

    lightened_pixel = tuple(
        [int(colour + coef * (MAX_COLOR_VALUE - colour)) for colour in pixel])

    return lightened_pixel


def lighten(image, coef):

    result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]

    return result


def darken_pixel(pixel, coef):

    darkened_pixel = tuple([int(colour - coef * (colour - 0))
                           for colour in pixel])

    return darkened_pixel


def darken(image, coef):

    result = [[darken_pixel(item, coef) for item in row] for row in image]

    return result


def invert_pixel(pixel):

    inverted_pixel = tuple([MAX_COLOR_VALUE - colour for colour in pixel])

    return inverted_pixel


def invert(image):

    result = [[invert_pixel(pixel) for pixel in row] for row in image]

    return result

Кристина обнови решението на 14.03.2016 14:30 (преди почти 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
74
75
76
77
78
79
80
81
82
83
84
85
import collections

MAX_COLOR_VALUE = 255


def create_histogram(image):

    result = {}

    result['red'] = collections.defaultdict(int)
    result['green'] = collections.defaultdict(int)
    result['blue'] = collections.defaultdict(int)

    for row in image:
        for (red, green, blue) in row:
            result['red'][red] += 1
            result['green'][green] += 1
            result['blue'][blue] += 1

    return result


def rotate_left(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[row][columns - col - 1]
               for row in range(rows)] for col in range(columns)]

    return result


def rotate_right(image):

    columns = len(image[0])
    rows = len(image)

    result = [[image[rows - row - 1][col]
               for row in range(rows)] for col in range(columns)]

    return result


def lighten_pixel(pixel, coef):

    lightened_pixel = tuple(
        [int(color + coef * (MAX_COLOR_VALUE - color)) for color in pixel])

    return lightened_pixel


def lighten(image, coef):

    result = [[lighten_pixel(pixel, coef) for pixel in row] for row in image]

    return result


def darken_pixel(pixel, coef):

    darkened_pixel = tuple([int(color - (coef * color)) for color in pixel])

    return darkened_pixel


def darken(image, coef):

    result = [[darken_pixel(item, coef) for item in row] for row in image]

    return result


def invert_pixel(pixel):

    inverted_pixel = tuple([MAX_COLOR_VALUE - color for color in pixel])

    return inverted_pixel


def invert(image):

    result = [[invert_pixel(pixel) for pixel in row] for row in image]

    return result