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
def rotate_left(image):
    rotated_image = []
    for row in range(len(image)):
        rotated_image.append([])
        for col in range(len(image[row])):
            rotated_image[row].append(image[col][len(image) - row - 1])
    return rotated_image


def rotate_right(image):
    rotated_image = []
    for row in range(len(image)):
        rotated_image.append([])
        for col in range(len(image[row])):
            rotated_image[row].append(image[len(image) - col - 1][row])
    return rotated_image


def invert(image):
    inverted_image = []
    for row in range(len(image)):
        inverted_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = 255 - pixel[i]
            inverted_image[row].append(tuple(pixel))
    return inverted_image


def lighten(image, coeff):
    lightened_image = []
    for row in range(len(image)):
        lightened_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = int(pixel[i] + coeff * (255 - pixel[i]))
            lightened_image[row].append(tuple(pixel))
    return lightened_image


def darken(image, coeff):
    darkened_image = []
    for row in range(len(image)):
        darkened_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = int(pixel[i] - coeff * (pixel[i] - 0))
            darkened_image[row].append(tuple(pixel))
    return darkened_image


def create_histogram(image):
    rgb_colors = ['red', 'green', 'blue']
    histogram = {color: {} for color in rgb_colors}

    for row in range(len(image)):
        for red, green, blue in image[row]:
            if red in histogram[rgb_colors[0]]:
                histogram[rgb_colors[0]][red] += 1
            else:
                histogram[rgb_colors[0]][red] = 1

            if green in histogram[rgb_colors[1]]:
                histogram[rgb_colors[1]][green] += 1
            else:
                histogram[rgb_colors[1]][green] = 1

            if blue in histogram[rgb_colors[2]]:
                histogram[rgb_colors[2]][blue] += 1
            else:
                histogram[rgb_colors[2]][blue] = 1
    return histogram

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

.........E.E
======================================================================
ERROR: test_rotate_left_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
IndexError: list index out of range

======================================================================
ERROR: test_rotate_right_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
IndexError: list index out of range

----------------------------------------------------------------------
Ran 12 tests in 0.086s

FAILED (errors=2)

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

Марина обнови решението на 14.03.2016 01:06 (преди почти 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
def rotate_left(image):
    rotated_image = []
    for row in range(len(image)):
        rotated_image.append([])
        for col in range(len(image[row])):
            rotated_image[row].append(image[col][len(image) - row - 1])
    return rotated_image


def rotate_right(image):
    rotated_image = []
    for row in range(len(image)):
        rotated_image.append([])
        for col in range(len(image[row])):
            rotated_image[row].append(image[len(image) - col - 1][row])
    return rotated_image


def invert(image):
    inverted_image = []
    for row in range(len(image)):
        inverted_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = 255 - pixel[i]
            inverted_image[row].append(tuple(pixel))
    return inverted_image


def lighten(image, coeff):
    lightened_image = []
    for row in range(len(image)):
        lightened_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = int(pixel[i] + coeff * (255 - pixel[i]))
            lightened_image[row].append(tuple(pixel))
    return lightened_image


def darken(image, coeff):
    darkened_image = []
    for row in range(len(image)):
        darkened_image.append([])
        for col in range(len(image[row])):
            pixel = list(image[row][col])
            for i in range(len(image[row][col])):
                pixel[i] = int(pixel[i] - coeff * (pixel[i] - 0))
            darkened_image[row].append(tuple(pixel))
    return darkened_image


def create_histogram(image):
    rgb_colors = ['red', 'green', 'blue']
    histogram = {color: {} for color in rgb_colors}

    for row in range(len(image)):
        for red, green, blue in image[row]:
            if red in histogram[rgb_colors[0]]:
                histogram[rgb_colors[0]][red] += 1
            else:
                histogram[rgb_colors[0]][red] = 1

            if green in histogram[rgb_colors[1]]:
                histogram[rgb_colors[1]][green] += 1
            else:
                histogram[rgb_colors[1]][green] = 1

            if blue in histogram[rgb_colors[2]]:
                histogram[rgb_colors[2]][blue] += 1
            else:
                histogram[rgb_colors[2]][blue] = 1
    return histogram