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_left(M):
    rotated = list(zip(*M))[::-1]
    return rotated


def rotate_right(M):
    rotated = list(zip(*M[::-1]))
    return rotated


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


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


def darken(M, coeficient):
    darkenI = []
    for pixels in M:
        darken.append(list(map(list, pixels)))
    for pixels in darken:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenII = []
    for pixels in darkenI:
        darkenII.append(list(map(tuple, pixels)))
    return darkenII


def create_histogram(M):
    histogram = {'red': {}, 'green': {}, 'blue': {}, }
    for pixels in M:
        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
AttributeError: 'function' object has no attribute 'append'

======================================================================
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
AttributeError: 'function' object has no attribute 'append'

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

FAILED (errors=2)

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

Иван обнови решението на 13.03.2016 22: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 rotate_left(M):
    rotated = list(zip(*M))[::-1]
    return rotated


def rotate_right(M):
    rotated = list(zip(*M[::-1]))
    return rotated


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


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


def darken(M, coeficient):
    darkenI = []
    for pixels in M:
        darken.append(list(map(list, pixels)))
    for pixels in darken:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenII = []
    for pixels in darkenI:
        darkenII.append(list(map(tuple, pixels)))
    return darkenII

Иван обнови решението на 14.03.2016 15: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_left(M):
    rotated = list(zip(*M))[::-1]
    return rotated


def rotate_right(M):
    rotated = list(zip(*M[::-1]))
    return rotated


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


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


def darken(M, coeficient):
    darkenI = []
    for pixels in M:
        darken.append(list(map(list, pixels)))
    for pixels in darken:
        for pixel in pixels:
            for index in range(0, len(pixel)):
                pixel[index] = (pixel[index] - int(coeficient*(pixel[index])))
    darkenII = []
    for pixels in darkenI:
        darkenII.append(list(map(tuple, pixels)))
    return darkenII


def create_histogram(M):
    histogram = {'red': {}, 'green': {}, 'blue': {}, }
    for pixels in M:
        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