Решение на Работа с картинки от Ангел Новоселски

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

Към профила на Ангел Новоселски

Резултати

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

Код

def rotate_right(image):
rotated = list(zip(*image[::-1]))
return rotated
def rotate_left(image):
rotated = list(zip(*image))[::-1]
return rotated
def darken(image, coeficient):
dark = []
for ps in image:
dark.append(list(map(list, ps)))
for ps in dark:
for p in ps:
for i in range(0, len(p)):
p[i] = (p[i] - int(coeficient*(p[i])))
darkTuple = []
for ps in dark:
darkTuple.append(list(map(tuple, ps)))
return darkTuple
def lighten(image, coeficient):
light = []
for ps in image:
light.append(list(map(list, ps)))
for ps in light:
for p in ps:
for i in range(0, len(p)):
p[i] = (
p[i] + int(coeficient*(255-p[i])))
lightTuple = []
for ps in light:
lightTuple.append(list(map(tuple, ps)))
return lightTuple
def invert(image):
inv = []
for ps in image:
inv.append(list(map(list, ps)))
for ps in inv:
for p in ps:
for i in range(0, len(p)):
p[i] = (255-p[i])
invTuple = []
for ps in inv:
invTuple.append(list(map(tuple, ps)))
return invTuple
def create_histogram(image):
histogram = {}
histogram['red'] = {}
histogram['green'] = {}
histogram['blue'] = {}
for ps in image:
for p in ps:
for i in range(0, len(p)):
if(i == 0):
if(p[i] in histogram['red']):
histogram['red'][p[i]] = 1 + histogram['red'][p[i]]
else:
histogram['red'][p[i]] = 1
if(i == 1):
if(p[i] in histogram['green']):
histogram['green'][p[i]] = 1 + histogram['green'][p[i]]
else:
histogram['green'][p[i]] = 1
if(i == 2):
if(p[i] in histogram['blue']):
histogram['blue'][p[i]] = 1 + histogram['blue'][p[i]]
else:
histogram['blue'][p[i]] = 1
return histogram

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.084s

OK

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

Ангел обнови решението на 14.03.2016 16:24 (преди над 5 години)

+def rotate_right(image):
+ rotated = list(zip(*image[::-1]))
+ return rotated
+
+
+def rotate_left(image):
+ rotated = list(zip(*image))[::-1]
+ return rotated
+
+
+def darken(image, coeficient):
+ dark = []
+ for ps in image:
+ dark.append(list(map(list, ps)))
+ for ps in dark:
+ for p in ps:
+ for i in range(0, len(p)):
+ p[i] = (p[i] - int(coeficient*(p[i])))
+ darkTuple = []
+ for ps in dark:
+ darkTuple.append(list(map(tuple, ps)))
+ return darkTuple
+
+
+def lighten(image, coeficient):
+ light = []
+ for ps in image:
+ light.append(list(map(list, ps)))
+ for ps in light:
+ for p in ps:
+ for i in range(0, len(p)):
+ p[i] = (
+ p[i] + int(coeficient*(255-p[i])))
+ lightTuple = []
+ for ps in light:
+ lightTuple.append(list(map(tuple, ps)))
+ return lightTuple
+
+
+def invert(image):
+ inv = []
+ for ps in image:
+ inv.append(list(map(list, ps)))
+ for ps in inv:
+ for p in ps:
+ for i in range(0, len(p)):
+ p[i] = (255-p[i])
+ invTuple = []
+ for ps in inv:
+ invTuple.append(list(map(tuple, ps)))
+ return invTuple
+
+
+def create_histogram(image):
+ histogram = {}
+ histogram['red'] = {}
+ histogram['green'] = {}
+ histogram['blue'] = {}
+ for ps in image:
+ for p in ps:
+ for i in range(0, len(p)):
+ if(i == 0):
+ if(p[i] in histogram['red']):
+ histogram['red'][p[i]] = 1 + histogram['red'][p[i]]
+ else:
+ histogram['red'][p[i]] = 1
+ if(i == 1):
+ if(p[i] in histogram['green']):
+ histogram['green'][p[i]] = 1 + histogram['green'][p[i]]
+ else:
+ histogram['green'][p[i]] = 1
+ if(i == 2):
+ if(p[i] in histogram['blue']):
+ histogram['blue'][p[i]] = 1 + histogram['blue'][p[i]]
+ else:
+ histogram['blue'][p[i]] = 1
+ return histogram