Решение на Работа с картинки от Стилиян Стоянов

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

Към профила на Стилиян Стоянов

Резултати

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

Код

def rotate_right(image):
new_image = []
[new_image.append(row[::-1]) for row in zip(*image)]
return new_image
def negate(pixel):
return(tuple(255 - value for value in pixel))
def rotate_left(image):
new_image = []
[new_image.append(row) for row in zip(*image)]
return(new_image[::-1])
def invert(image):
return [[negate(pixel) for pixel in row] for row in image]
def lighten(image, coeff):
return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]
def lighter_pixel(pixel, coeff):
return tuple(int(color + coeff * (255 - color)) for color in pixel)
def darken(image, coeff):
return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]
def darken_pixel(pixel, coeff):
return tuple(int(color - coeff * color) for color in pixel)
def create_histogram(image):
histogram = {}
histogram['red'] = {}
histogram['green'] = {}
histogram['blue'] = {}
for row in image:
for pixel in row:
r, g, b = pixel[0], pixel[1], pixel[2]
if r in histogram['red']:
histogram['red'][r] = histogram['red'][r] + 1
else:
histogram['red'][r] = 1
if g in histogram['green']:
histogram['green'][g] = histogram['green'][g] + 1
else:
histogram['green'][g] = 1
if b in histogram['blue']:
histogram['blue'][b] = histogram['blue'][b] + 1
else:
histogram['blue'][b] = 1
return histogram

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

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

OK

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

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

+from collections import defaultdict
+
+
+def rotate_right(image):
+ new_image = []
+ [new_image.append(row[::-1]) for row in zip(*image)]
+ return new_image
+
+
+def negate(pixel):
+ return(tuple(255 - value for value in pixel))
+
+
+def rotate_left(image):
+ new_image = []
+ [new_image.append(row) for row in zip(*image)]
+ return(new_image[::-1])
+
+
+def invert(image):
+ return [[negate(pixel) for pixel in row] for row in image]
+
+
+def lighten(image, coeff):
+ return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]
+
+
+def lighter_pixel(pixel, coeff):
+ return tuple(int(color + coeff * (255 - color)) for color in pixel)
+
+
+def darken(image, coeff):
+ return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]
+
+
+def darken_pixel(pixel, coeff):
+ return tuple(int(color - coeff * color) for color in pixel)
+
+
+def create_default_histogram(image):
+ histogram = {}
+ return histogram
+
+
+def create_histogram(image):
+ histogram = {}
+ histogram['red'] = {}
+ histogram['green'] = {}
+ histogram['blue'] = {}
+ for row in image:
+ for pixel in row:
+ r, g, b = pixel[0], pixel[1], pixel[2]
+ if r in histogram['red']:
+ histogram['red'][r] = histogram['red'][r] + 1
+ else:
+ histogram['red'][r] = 1
+
+ if g in histogram['green']:
+ histogram['green'][g] = histogram['green'][g] + 1
+ else:
+ histogram['green'][g] = 1
+ if b in histogram['blue']:
+ histogram['blue'][b] = histogram['blue'][b] + 1
+ else:
+ histogram['blue'][b] = 1
+ return histogram

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

-from collections import defaultdict
-
-
-def rotate_right(image):
- new_image = []
- [new_image.append(row[::-1]) for row in zip(*image)]
- return new_image
-
-
-def negate(pixel):
- return(tuple(255 - value for value in pixel))
-
-
+from collections import defaultdict
+
+
+def rotate_right(image):
+ new_image = []
+ [new_image.append(row[::-1]) for row in zip(*image)]
+ return new_image
+
+
+def negate(pixel):
+ return(tuple(255 - value for value in pixel))
+
+
def rotate_left(image):
new_image = []
[new_image.append(row) for row in zip(*image)]
return(new_image[::-1])
def invert(image):
return [[negate(pixel) for pixel in row] for row in image]
def lighten(image, coeff):
return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]
def lighter_pixel(pixel, coeff):
return tuple(int(color + coeff * (255 - color)) for color in pixel)
def darken(image, coeff):
return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]
def darken_pixel(pixel, coeff):
return tuple(int(color - coeff * color) for color in pixel)
def create_default_histogram(image):
histogram = {}
return histogram
def create_histogram(image):
histogram = {}
histogram['red'] = {}
histogram['green'] = {}
histogram['blue'] = {}
for row in image:
for pixel in row:
r, g, b = pixel[0], pixel[1], pixel[2]
if r in histogram['red']:
histogram['red'][r] = histogram['red'][r] + 1
else:
histogram['red'][r] = 1
if g in histogram['green']:
histogram['green'][g] = histogram['green'][g] + 1
else:
histogram['green'][g] = 1
if b in histogram['blue']:
histogram['blue'][b] = histogram['blue'][b] + 1
else:
histogram['blue'][b] = 1
return histogram

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

-from collections import defaultdict
-
-
-def rotate_right(image):
+def rotate_right(image):
new_image = []
[new_image.append(row[::-1]) for row in zip(*image)]
return new_image
def negate(pixel):
return(tuple(255 - value for value in pixel))
def rotate_left(image):
new_image = []
[new_image.append(row) for row in zip(*image)]
return(new_image[::-1])
def invert(image):
return [[negate(pixel) for pixel in row] for row in image]
def lighten(image, coeff):
return [[lighter_pixel(pixel, coeff) for pixel in row] for row in image]
def lighter_pixel(pixel, coeff):
return tuple(int(color + coeff * (255 - color)) for color in pixel)
def darken(image, coeff):
return[[darken_pixel(pixel, coeff) for pixel in row] for row in image]
def darken_pixel(pixel, coeff):
return tuple(int(color - coeff * color) for color in pixel)
-def create_default_histogram(image):
- histogram = {}
- return histogram
-
-
def create_histogram(image):
histogram = {}
histogram['red'] = {}
histogram['green'] = {}
histogram['blue'] = {}
for row in image:
for pixel in row:
r, g, b = pixel[0], pixel[1], pixel[2]
if r in histogram['red']:
- histogram['red'][r] = histogram['red'][r] + 1
+ histogram['red'][r] = histogram['red'][r] + 1
else:
- histogram['red'][r] = 1
-
+ histogram['red'][r] = 1
if g in histogram['green']:
- histogram['green'][g] = histogram['green'][g] + 1
+ histogram['green'][g] = histogram['green'][g] + 1
else:
- histogram['green'][g] = 1
+ histogram['green'][g] = 1
if b in histogram['blue']:
- histogram['blue'][b] = histogram['blue'][b] + 1
+ histogram['blue'][b] = histogram['blue'][b] + 1
else:
- histogram['blue'][b] = 1
+ histogram['blue'][b] = 1
return histogram

Изтрих импорт-а за последното качено решение, но при копирането по някакъв начин са се получили trailing whitespace: solution.py:1:25: W291 trailing whitespace solution.py:46:62: W291 trailing whitespace solution.py:48:40: W291 trailing whitespace solution.py:50:66: W291 trailing whitespace solution.py:52:42: W291 trailing whitespace solution.py:54:64: W291 trailing whitespace solution.py:56:41: W291 trailing whitespace

Предпоследното качено няма този проблем...