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
def invert_color(pixel):
    return(
        255 - pixel[0],
        255 - pixel[1],
        255 - pixel[2]
        )


def invert(picture):
    return [[invert_color(pixel) for pixel in row] for row in picture]


def rotate_right(picture):
    return [list(x) for x in zip(*picture[::-1])]


def rotate_left(picture):
    return [list(x) for x in zip(*picture)][::-1]


def lighten_single(color, factor):
    new = color + factor * (255 - color)
    if new > 255:
        return 255
    else:
        return int(new)


def lighten_pixel(pixel, factor):
    return (
        lighten_single(pixel[0], factor),
        lighten_single(pixel[1], factor),
        lighten_single(pixel[2], factor)
        )


def darken_pixel(pixel, factor):
    return (
        int(pixel[0] * (1 - factor)),
        int(pixel[1] * (1 - factor)),
        int(pixel[2] * (1 - factor))
        )


def lighten(picture, factor):
    return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]


def darken(picture, factor):
    return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]


def partial_histogram(picture, i):
    partial = {}
    for row in picture:
        for pixel in row:
            if pixel[i] in partial:
                partial[pixel[i]] = partial[pixel[i]] + 1
            else:
                partial[pixel[i]] = 1
    return partial


def create_histogram(picture):
    return {
        'red': partial_histogram(picture, 0),
        'green': partial_histogram(picture, 1),
        'blue': partial_histogram(picture, 2)
        }

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

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

OK

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

Теодор обнови решението на 08.03.2016 15:57 (преди почти 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
def invert_color(pixel):
    return(255 - pixel[0], 
           255 - pixel[1], 
           255 - pixel[2])

def invert(picture):
    return [[invert_color(pixel) for pixel in row] for row in picture] 

def rotate_right(picture): 
    return [list(x) for x in zip(*picture[::-1])] 

def rotate_left (picture): 
    return [list(x) for x in zip(*picture)][::-1] 

def lighten_single (color, factor):
    new = color + factor * (255 - color)
    if new > 255 : 
        return 255
    else :
        return int(new)

def lighten_pixel (pixel, factor):
    return (lighten_single(pixel[0], factor), 
            lighten_single(pixel[1], factor), 
            lighten_single(pixel[2], factor) )

def darken_pixel (pixel, factor):
    return (int(pixel[0] * (1 - factor)),
            int(pixel[1] * (1 - factor)),
            int(pixel[2] * (1 - factor)))

def lighten (picture, factor):
    return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]

def darken (picture, factor):
    return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]

def partial_histogram(picture, i):
        partial = {}
        for row in picture:
                for pixel in row:
                        if pixel[i] in partial:
                                partial[pixel[i]] = partial[pixel[i]] + 1
                        else:
                                partial[pixel[i]] = 1
        return partial

def create_histogram(picture):
    return {'red': partial_histogram(picture, 0),
            'green': partial_histogram(picture, 1),
            'blue': partial_histogram(picture, 2)}

Теодор обнови решението на 09.03.2016 00:38 (преди почти 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
def invert_color(pixel):
    return(255 - pixel[0],
           255 - pixel[1],
           255 - pixel[2])


def invert(picture):
    return [[invert_color(pixel) for pixel in row] for row in picture]


def rotate_right(picture):
    return [list(x) for x in zip(*picture[::-1])]


def rotate_left(picture):
    return [list(x) for x in zip(*picture)][::-1]


def lighten_single(color, factor):
    new = color + factor * (255 - color)
    if new > 255:
        return 255
    else:
        return int(new)


def lighten_pixel(pixel, factor):
    return (lighten_single(pixel[0], factor),
            lighten_single(pixel[1], factor),
            lighten_single(pixel[2], factor))


def darken_pixel(pixel, factor):
    return (int(pixel[0] * (1 - factor)),
            int(pixel[1] * (1 - factor)),
            int(pixel[2] * (1 - factor)))


def lighten(picture, factor):
    return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]


def darken(picture, factor):
    return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]


def partial_histogram(picture, i):
    partial = {}
    for row in picture:
        for pixel in row:
            if pixel[i] in partial:
                partial[pixel[i]] = partial[pixel[i]] + 1
            else:
                partial[pixel[i]] = 1
    return partial


def create_histogram(picture):
    return {'red': partial_histogram(picture, 0),
            'green': partial_histogram(picture, 1),
            'blue': partial_histogram(picture, 2)}

Теодор обнови решението на 11.03.2016 19:31 (преди почти 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
def invert_color(pixel):
    return(
        255 - pixel[0],
        255 - pixel[1],
        255 - pixel[2]
        )


def invert(picture):
    return [[invert_color(pixel) for pixel in row] for row in picture]


def rotate_right(picture):
    return [list(x) for x in zip(*picture[::-1])]


def rotate_left(picture):
    return [list(x) for x in zip(*picture)][::-1]


def lighten_single(color, factor):
    new = color + factor * (255 - color)
    if new > 255:
        return 255
    else:
        return int(new)


def lighten_pixel(pixel, factor):
    return (
        lighten_single(pixel[0], factor),
        lighten_single(pixel[1], factor),
        lighten_single(pixel[2], factor)
        )


def darken_pixel(pixel, factor):
    return (
        int(pixel[0] * (1 - factor)),
        int(pixel[1] * (1 - factor)),
        int(pixel[2] * (1 - factor))
        )


def lighten(picture, factor):
    return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]


def darken(picture, factor):
    return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]


def partial_histogram(picture, i):
    partial = {}
    for row in picture:
        for pixel in row:
            if pixel[i] in partial:
                partial[pixel[i]] = partial[pixel[i]] + 1
            else:
                partial[pixel[i]] = 1
    return partial


def create_histogram(picture):
    return {
        'red': partial_histogram(picture, 0),
        'green': partial_histogram(picture, 1),
        'blue': partial_histogram(picture, 2)
        }