Решение на Работа с картинки от Иван Камбуров

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

Към профила на Иван Камбуров

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 12 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def rotate_left(image):
return_image = [
[image[y][-x] for y in range(len(image))]
for x in range(1, len(image[0]) + 1)
]
return return_image
def rotate_right(image):
return_image = [
[image[-y][x] for y in range(1, len(image) + 1)]
for x in range(len(image[0]))
]
return return_image
def invert(image):
return_image = [
[(255 - col[0], 255 - col[1], 255 - col[2]) for col in row]
for row in image
]
return return_image
def lighten(image, coeff):
return_image = [
[
((int)(col[0] + coeff*(255 - col[0])),
(int)(col[1] + coeff*(255 - col[1])),
(int)(col[2] + coeff*(255 - col[2])))
for col in row
]
for row in image
]
return return_image
def darken(image, coeff):
return_image = [
[
(col[0] - (int)(coeff*col[0]),
col[1] - (int)(coeff*col[1]),
col[2] - (int)(coeff*col[2]))
for col in row
]
for row in image
]
return return_image
def create_histogram(image):
red = {i: 0 for i in range(256)}
green = {i: 0 for i in range(256)}
blue = {i: 0 for i in range(256)}
for x in range(len(image)):
for y in range(len(image[0])):
red[image[x][y][0]] += 1
green[image[x][y][1]] += 1
blue[image[x][y][2]] += 1
histogram = {
'red': {i: red[i] for i in range(256) if red[i] != 0},
'green': {i: green[i] for i in range(256) if green[i] != 0},
'blue': {i: blue[i] for i in range(256) if blue[i] != 0}
}
return histogram

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.092s

OK

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

Иван обнови решението на 14.03.2016 11:36 (преди над 5 години)

+def rotate_left(image):
+ return_image = [
+ [image[y][-x] for y in range(len(image))]
+ for x in range(1, len(image[0]) + 1)
+ ]
+ return return_image
+
+
+def rotate_right(image):
+ return_image = [
+ [image[-y][x] for y in range(1, len(image) + 1)]
+ for x in range(len(image[0]))
+ ]
+ return return_image
+
+
+def invert(image):
+ return_image = [
+ [(255 - col[0], 255 - col[1], 255 - col[2]) for col in row]
+ for row in image
+ ]
+ return return_image
+
+
+def lighten(image, coeff):
+ return_image = [
+ [
+ ((int)(col[0] + coeff*(255 - col[0])),
+ (int)(col[1] + coeff*(255 - col[1])),
+ (int)(col[2] + coeff*(255 - col[2])))
+ for col in row
+ ]
+ for row in image
+ ]
+ return return_image
+
+
+def darken(image, coeff):
+ return_image = [
+ [
+ (col[0] - (int)(coeff*col[0]),
+ col[1] - (int)(coeff*col[1]),
+ col[2] - (int)(coeff*col[2]))
+ for col in row
+ ]
+ for row in image
+ ]
+ return return_image
+
+
+def create_histogram(image):
+ red = {i: 0 for i in range(256)}
+ green = {i: 0 for i in range(256)}
+ blue = {i: 0 for i in range(256)}
+ for x in range(len(image)):
+ for y in range(len(image[0])):
+ red[image[x][y][0]] += 1
+ green[image[x][y][1]] += 1
+ blue[image[x][y][2]] += 1
+ histogram = {
+ 'red': {i: red[i] for i in range(256) if red[i] != 0},
+ 'green': {i: green[i] for i in range(256) if green[i] != 0},
+ 'blue': {i: blue[i] for i in range(256) if blue[i] != 0}
+ }
+ return histogram