timeit

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

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

Решение на Работа с картинки от Антон Пенов

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

Към профила на Антон Пенов

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 10 успешни тест(а)
  • 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
def rotate_right(original):
    rotated = list(zip(*original[::-1]))
    return rotated


def rotate_left(original):
    rotated = list(zip(*original))[::-1]
    return rotated


def invert(original):
    inverted = list()
    for pixels in original:
        inverted.append(list(map(list, pixels)))
    for pixels in inverted:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (255-pixel[index])
    invertedInTuple = list()
    for pixels in inverted:
        invertedInTuple.append(list(map(tuple, pixels)))
    return invertedInTuple


def darken(original, coeficient):
    darkened = list()
    for pixels in original:
        darkened.append(list(map(list, pixels)))
    for pixels in darkened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenedInTuple = list()
    for pixels in darkened:
        darkenInTuple.append(list(map(tuple, pixels)))
    return darkenInTuple


def lighten(original, coeficient):
    lightened = list()
    for pixels in original:
        lightened.append(list(map(list, pixels)))
    for pixels in lightened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (
                    pixel[index] + int(coeficient*(255-pixel[index])))
    lightenedInTuple = list()
    for pixels in lightened:
        lightenedInTuple.append(list(map(tuple, pixels)))
    return lightenedInTuple


def create_histogram(original):
    histogram = dict()
    histogram['red'] = dict()
    histogram['green'] = dict()
    histogram['blue'] = dict()
    for pixels in original:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                if(index == 0):
                    if(pixel[index] in histogram['red']):
                        histogram['red'][pixel[index]] = 1 + histogram['red'][pixel[index]]
                    else:
                        histogram['red'][pixel[index]] = 1
                if(index == 1):
                    if(pixel[index] in histogram['green']):
                        histogram['green'][pixel[index]] = 1 + histogram['green'][pixel[index]]
                    else:
                        histogram['green'][pixel[index]] = 1
                if(index == 2):
                    if(pixel[index] in histogram['blue']):
                        histogram['blue'][pixel[index]] = 1 + histogram['blue'][pixel[index]]
                    else:
                        histogram['blue'][pixel[index]] = 1
    return histogram

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

..EE........
======================================================================
ERROR: test_darken (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
NameError: name 'darkenInTuple' is not defined

======================================================================
ERROR: test_darken_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
NameError: name 'darkenInTuple' is not defined

----------------------------------------------------------------------
Ran 12 tests in 0.085s

FAILED (errors=2)

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

Антон обнови решението на 14.03.2016 15: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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def rotate_right(original):
    rotated = list(zip(*original[::-1]))
    return rotated


def rotate_left(original):
    rotated = list(zip(*original))[::-1]
    return rotated


def invert(original):
    inverted = list()
    for pixels in original:
        inverted.append(list(map(list, pixels)))
    for pixels in inverted:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (255-pixel[index])
    invertedInTuple = list()
    for pixels in inverted:
        invertedInTuple.append(list(map(tuple, pixels)))
    return invertedInTuple


def darken(original, coeficient):
    darkened = list()
    for pixels in original:
        darken.append(list(map(list, pixels)))
    for pixels in darkened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenedInTuple = list()
    for pixels in darkened:
        darkenInTuple.append(list(map(tuple, pixels)))
    return darkenInTuple


def lighten(original, coeficient):
    lightened = list()
    for pixels in original:
        lightened.append(list(map(list, pixels)))
    for pixels in lightened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (
                    pixel[index] + int(coeficient*(255-pixel[index])))
    lightenedInTuple = list()
    for pixels in lightened:
        lightenedInTuple.append(list(map(tuple, pixels)))
    return lightenedInTuple


def create_histogram(original):
    histogram = dict()
    histogram['red'] = dict()
    histogram['green'] = dict()
    histogram['blue'] = dict()
    for pixels in original:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                if(index == 0):
                    if(pixel[index] in histogram['red']):
                        histogram['red'][pixel[index]] = 1 + histogram['red'][pixel[index]]
                    else:
                        histogram['red'][pixel[index]] = 1
                if(index == 1):
                    if(pixel[index] in histogram['green']):
                        histogram['green'][pixel[index]] = 1 + histogram['green'][pixel[index]]
                    else:
                        histogram['green'][pixel[index]] = 1
                if(index == 2):
                    if(pixel[index] in histogram['blue']):
                        histogram['blue'][pixel[index]] = 1 + histogram['blue'][pixel[index]]
                    else:
                        histogram['blue'][pixel[index]] = 1
    return histogram

Антон обнови решението на 14.03.2016 16:12 (преди почти 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
def rotate_right(original):
    rotated = list(zip(*original[::-1]))
    return rotated


def rotate_left(original):
    rotated = list(zip(*original))[::-1]
    return rotated


def invert(original):
    inverted = list()
    for pixels in original:
        inverted.append(list(map(list, pixels)))
    for pixels in inverted:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (255-pixel[index])
    invertedInTuple = list()
    for pixels in inverted:
        invertedInTuple.append(list(map(tuple, pixels)))
    return invertedInTuple


def darken(original, coeficient):
    darkened = list()
    for pixels in original:
        darkened.append(list(map(list, pixels)))
    for pixels in darkened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenedInTuple = list()
    for pixels in darkened:
        darkenInTuple.append(list(map(tuple, pixels)))
    return darkenInTuple


def lighten(original, coeficient):
    lightened = list()
    for pixels in original:
        lightened.append(list(map(list, pixels)))
    for pixels in lightened:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (
                    pixel[index] + int(coeficient*(255-pixel[index])))
    lightenedInTuple = list()
    for pixels in lightened:
        lightenedInTuple.append(list(map(tuple, pixels)))
    return lightenedInTuple


def create_histogram(original):
    histogram = dict()
    histogram['red'] = dict()
    histogram['green'] = dict()
    histogram['blue'] = dict()
    for pixels in original:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                if(index == 0):
                    if(pixel[index] in histogram['red']):
                        histogram['red'][pixel[index]] = 1 + histogram['red'][pixel[index]]
                    else:
                        histogram['red'][pixel[index]] = 1
                if(index == 1):
                    if(pixel[index] in histogram['green']):
                        histogram['green'][pixel[index]] = 1 + histogram['green'][pixel[index]]
                    else:
                        histogram['green'][pixel[index]] = 1
                if(index == 2):
                    if(pixel[index] in histogram['blue']):
                        histogram['blue'][pixel[index]] = 1 + histogram['blue'][pixel[index]]
                    else:
                        histogram['blue'][pixel[index]] = 1
    return histogram