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
def rotate_right(image):                                                                                                                                                                                                                     
    new_image = []
    [new_image.append(row[::-1]) for row in zip(*image)]
    return new_image


def negate(pixel):
    return(tuple(255 - value for value in pixel))


def rotate_left(image):
    new_image = []
    [new_image.append(row) for row in zip(*image)]
    return(new_image[::-1])


def invert(image):
    return [[negate(pixel) for pixel in row] for row in image]


def lighten(image, coeff):
    return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]


def lighter_pixel(pixel, coeff):
    return tuple(int(color + coeff * (255 - color)) for color in pixel)


def darken(image, coeff):
    return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]


def darken_pixel(pixel, coeff):
    return tuple(int(color - coeff * color) for color in pixel)


def create_histogram(image):
    histogram = {}
    histogram['red'] = {}
    histogram['green'] = {}
    histogram['blue'] = {}
    for row in image:
        for pixel in row:
            r, g, b = pixel[0], pixel[1], pixel[2]
            if r in histogram['red']:
                histogram['red'][r] = histogram['red'][r] + 1 
            else:
                histogram['red'][r] = 1 
            if g in histogram['green']:
                histogram['green'][g] = histogram['green'][g] + 1 
            else:
                histogram['green'][g] = 1 
            if b in histogram['blue']:
                histogram['blue'][b] = histogram['blue'][b] + 1 
            else:
                histogram['blue'][b] = 1 
    return histogram

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

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

OK

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

Стилиян обнови решението на 14.03.2016 16:52 (преди почти 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
from collections import defaultdict                                                                                                                                                                                                          
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
def rotate_right(image):                                                                                                                                                                                                                     
    new_image = []                                                                                                                                                                                                                           
    [new_image.append(row[::-1]) for row in zip(*image)]                                                                                                                                                                                     
    return new_image                                                                                                                                                                                                                         
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
def negate(pixel):                                                                                                                                                                                                                           
    return(tuple(255 - value for value in pixel))                                                                                                                                                                                            
                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
def rotate_left(image):
    new_image = []
    [new_image.append(row) for row in zip(*image)]
    return(new_image[::-1])


def invert(image):
    return [[negate(pixel) for pixel in row] for row in image]


def lighten(image, coeff):
    return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]


def lighter_pixel(pixel, coeff):
    return tuple(int(color + coeff * (255 - color)) for color in pixel)


def darken(image, coeff):
    return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]


def darken_pixel(pixel, coeff):
    return tuple(int(color - coeff * color) for color in pixel)


def create_default_histogram(image):
    histogram = {}
    return histogram


def create_histogram(image):
    histogram = {}
    histogram['red'] = {}
    histogram['green'] = {}
    histogram['blue'] = {}
    for row in image:
        for pixel in row:
            r, g, b = pixel[0], pixel[1], pixel[2]
            if r in histogram['red']:
                histogram['red'][r] = histogram['red'][r] + 1
            else:
                histogram['red'][r] = 1

            if g in histogram['green']:
                histogram['green'][g] = histogram['green'][g] + 1
            else:
                histogram['green'][g] = 1
            if b in histogram['blue']:
                histogram['blue'][b] = histogram['blue'][b] + 1
            else:
                histogram['blue'][b] = 1
    return histogram

Стилиян обнови решението на 14.03.2016 16:54 (преди почти 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
from collections import defaultdict


def rotate_right(image):
    new_image = []
    [new_image.append(row[::-1]) for row in zip(*image)]
    return new_image


def negate(pixel):
    return(tuple(255 - value for value in pixel))


def rotate_left(image):
    new_image = []
    [new_image.append(row) for row in zip(*image)]
    return(new_image[::-1])


def invert(image):
    return [[negate(pixel) for pixel in row] for row in image]


def lighten(image, coeff):
    return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]


def lighter_pixel(pixel, coeff):
    return tuple(int(color + coeff * (255 - color)) for color in pixel)


def darken(image, coeff):
    return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]


def darken_pixel(pixel, coeff):
    return tuple(int(color - coeff * color) for color in pixel)


def create_default_histogram(image):
    histogram = {}
    return histogram


def create_histogram(image):
    histogram = {}
    histogram['red'] = {}
    histogram['green'] = {}
    histogram['blue'] = {}
    for row in image:
        for pixel in row:
            r, g, b = pixel[0], pixel[1], pixel[2]
            if r in histogram['red']:
                histogram['red'][r] = histogram['red'][r] + 1
            else:
                histogram['red'][r] = 1

            if g in histogram['green']:
                histogram['green'][g] = histogram['green'][g] + 1
            else:
                histogram['green'][g] = 1
            if b in histogram['blue']:
                histogram['blue'][b] = histogram['blue'][b] + 1
            else:
                histogram['blue'][b] = 1
    return histogram

Стилиян обнови решението на 14.03.2016 16:58 (преди почти 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
def rotate_right(image):                                                                                                                                                                                                                     
    new_image = []
    [new_image.append(row[::-1]) for row in zip(*image)]
    return new_image


def negate(pixel):
    return(tuple(255 - value for value in pixel))


def rotate_left(image):
    new_image = []
    [new_image.append(row) for row in zip(*image)]
    return(new_image[::-1])


def invert(image):
    return [[negate(pixel) for pixel in row] for row in image]


def lighten(image, coeff):
    return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]


def lighter_pixel(pixel, coeff):
    return tuple(int(color + coeff * (255 - color)) for color in pixel)


def darken(image, coeff):
    return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]


def darken_pixel(pixel, coeff):
    return tuple(int(color - coeff * color) for color in pixel)


def create_histogram(image):
    histogram = {}
    histogram['red'] = {}
    histogram['green'] = {}
    histogram['blue'] = {}
    for row in image:
        for pixel in row:
            r, g, b = pixel[0], pixel[1], pixel[2]
            if r in histogram['red']:
                histogram['red'][r] = histogram['red'][r] + 1 
            else:
                histogram['red'][r] = 1 
            if g in histogram['green']:
                histogram['green'][g] = histogram['green'][g] + 1 
            else:
                histogram['green'][g] = 1 
            if b in histogram['blue']:
                histogram['blue'][b] = histogram['blue'][b] + 1 
            else:
                histogram['blue'][b] = 1 
    return histogram

Изтрих импорт-а за последното качено решение, но при копирането по някакъв начин са се получили trailing whitespace: solution.py:1:25: W291 trailing whitespace solution.py:46:62: W291 trailing whitespace solution.py:48:40: W291 trailing whitespace solution.py:50:66: W291 trailing whitespace solution.py:52:42: W291 trailing whitespace solution.py:54:64: W291 trailing whitespace solution.py:56:41: W291 trailing whitespace

Предпоследното качено няма този проблем...