Решение на Работа с картинки от Яница Велевска

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

Към профила на Яница Велевска

Резултати

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

Код

from collections import defaultdict
def rotate_left(img):
new = []
for j in range(len(img[0])-1, -1, -1):
some = []
for i in range(len(img)):
some.append(img[i][j])
new.append(some)
return new
def rotate_right(img):
new = []
for j in range(len(img[0])):
some = []
for i in range(len(img)-1, -1, -1):
some.append(img[i][j])
new.append(some)
return new
def invert(img):
new = []
for row in img:
some = []
for elem in row:
r = 255 - elem[0]
g = 255 - elem[1]
b = 255 - elem[2]
pixel = (r, g, b)
some.append(pixel)
new.append(some)
return new
def lighten(img, n):
new = []
for row in img:
some = []
for elem in row:
r = elem[0] + int(n * (255 - elem[0]))
g = elem[1] + int(n * (255 - elem[1]))
b = elem[2] + int(n * (255 - elem[2]))
pixel = (r, g, b)
some.append(pixel)
new.append(some)
return new
def darken(img, n):
new = []
for row in img:
some = []
for elem in row:
r = elem[0] - int(n * (elem[0]-0))
g = elem[1] - int(n * (elem[1]-0))
b = elem[2] - int(n * (elem[2]-0))
pixel = (r, g, b)
some.append(pixel)
new.append(some)
return new
def create_histogram(img):
histogram = {'red': defaultdict(int),
'green': defaultdict(int),
'blue': defaultdict(int)}
for row in img:
for elem in row:
histogram['red'][elem[0]] += 1
histogram['green'][elem[1]] += 1
histogram['blue'][elem[2]] += 1
return histogram

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.089s

OK

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

Яница обнови решението на 14.03.2016 14:36 (преди над 5 години)

+from collections import defaultdict
+
+
+def rotate_left(img):
+ new = []
+ for j in range(len(img[0])-1, -1, -1):
+ some = []
+ for i in range(len(img)):
+ some.append(img[i][j])
+ new.append(some)
+ return new
+
+
+def rotate_right(img):
+ new = []
+ for j in range(len(img[0])):
+ some = []
+ for i in range(len(img)-1, -1, -1):
+ some.append(img[i][j])
+ new.append(some)
+ return new
+
+
+def invert(img):
+ new = []
+ for row in img:
+ some = []
+ for elem in row:
+ r = 255 - elem[0]
+ g = 255 - elem[1]
+ b = 255 - elem[2]
+ pixel = (r, g, b)
+ some.append(pixel)
+ new.append(some)
+ return new
+
+
+def lighten(img, n):
+ new = []
+ for row in img:
+ some = []
+ for elem in row:
+ r = elem[0] + int(n * (255 - elem[0]))
+ g = elem[1] + int(n * (255 - elem[1]))
+ b = elem[2] + int(n * (255 - elem[2]))
+ pixel = (r, g, b)
+ some.append(pixel)
+ new.append(some)
+ return new
+
+
+def darken(img, n):
+ new = []
+ for row in img:
+ some = []
+ for elem in row:
+ r = elem[0] - int(n * (elem[0]-0))
+ g = elem[1] - int(n * (elem[1]-0))
+ b = elem[2] - int(n * (elem[2]-0))
+ pixel = (r, g, b)
+ some.append(pixel)
+ new.append(some)
+ return new
+
+
+def create_histogram(img):
+ histogram = {'red': defaultdict(int),
+ 'green': defaultdict(int),
+ 'blue': defaultdict(int)}
+ for row in img:
+ for elem in row:
+ histogram['red'][elem[0]] += 1
+ histogram['green'][elem[1]] += 1
+ histogram['blue'][elem[2]] += 1
+ return histogram