Решение на Работа с картинки от Ирина Христова

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

Към профила на Ирина Христова

Резултати

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

Код

def rotate_left(image):
rows = len(image)
columns = len(image[0])
rotated = []
for col in range(columns)[::-1]:
temp = []
for row in range(rows):
temp.append(image[row][col])
rotated.append(temp)
return rotated
def rotate_right(image):
rows = len(image)
columns = len(image[0])
rotated = []
for col in range(columns):
temp = []
for row in range(rows)[::-1]:
temp.append(image[row][col])
rotated.append(temp)
return rotated
def invert(image):
rows = len(image)
inv = []
for row in range(rows):
temp_row = []
for pixel in image[row]:
temp_rgb = ()
for rgb in pixel:
temp_rgb = temp_rgb + (255 - rgb,)
temp_row.append(temp_rgb)
inv.append(temp_row)
return inv
def lighten(image, n):
rows = len(image)
light = []
for row in range(rows):
temp_row = []
for pixel in image[row]:
temp_rgb = ()
for rgb in pixel:
temp_rgb = temp_rgb + (rgb + int(n * (255 - rgb)),)
temp_row.append(temp_rgb)
light.append(temp_row)
return light
def darken(image, n):
rows = len(image)
dark = []
for row in range(rows):
temp_row = []
for pixel in image[row]:
temp_rgb = ()
for rgb in pixel:
temp_rgb = temp_rgb + (rgb - int(n * rgb),)
temp_row.append(temp_rgb)
dark.append(temp_row)
return dark
def create_histogram(image):
hist = {'red': {}, 'green': {}, 'blue': {}}
colors = {0: 'red', 1: 'green', 2: 'blue'}
for row in range(len(image)):
for pixel in image[row]:
for i in range(3):
if pixel[i] in hist[colors[i]]:
hist[colors[i]][pixel[i]] += 1
else:
hist[colors[i]][pixel[i]] = 1
return hist

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.101s

OK

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

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

+def rotate_left(image):
+ rows = len(image)
+ columns = len(image[0])
+ rotated = []
+
+ for col in range(columns)[::-1]:
+ temp = []
+ for row in range(rows):
+ temp.append(image[row][col])
+ rotated.append(temp)
+
+ return rotated
+
+
+def rotate_right(image):
+ rows = len(image)
+ columns = len(image[0])
+ rotated = []
+
+ for col in range(columns):
+ temp = []
+ for row in range(rows)[::-1]:
+ temp.append(image[row][col])
+ rotated.append(temp)
+
+ return rotated
+
+
+def invert(image):
+ rows = len(image)
+ inv = []
+
+ for row in range(rows):
+ temp_row = []
+ for pixel in image[row]:
+ temp_rgb = ()
+ for rgb in pixel:
+ temp_rgb = temp_rgb + (255 - rgb,)
+ temp_row.append(temp_rgb)
+ inv.append(temp_row)
+
+ return inv
+
+
+def lighten(image, n):
+ rows = len(image)
+ light = []
+
+ for row in range(rows):
+ temp_row = []
+ for pixel in image[row]:
+ temp_rgb = ()
+ for rgb in pixel:
+ temp_rgb = temp_rgb + (rgb + int(n * (255 - rgb)),)
+ temp_row.append(temp_rgb)
+ light.append(temp_row)
+
+ return light
+
+
+def darken(image, n):
+ rows = len(image)
+ dark = []
+
+ for row in range(rows):
+ temp_row = []
+ for pixel in image[row]:
+ temp_rgb = ()
+ for rgb in pixel:
+ temp_rgb = temp_rgb + (rgb - int(n * rgb),)
+ temp_row.append(temp_rgb)
+ dark.append(temp_row)
+
+ return dark
+
+
+def create_histogram(image):
+ hist = {'red': {}, 'green': {}, 'blue': {}}
+ colors = {0: 'red', 1: 'green', 2: 'blue'}
+
+ for row in range(len(image)):
+ for pixel in image[row]:
+ for i in range(3):
+ if pixel[i] in hist[colors[i]]:
+ hist[colors[i]][pixel[i]] += 1
+ else:
+ hist[colors[i]][pixel[i]] = 1
+
+ return hist