Решение на Работа с картинки от Христо Владев

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

Към профила на Христо Владев

Резултати

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

Код

from collections import defaultdict
def rotate_left(image):
return list(zip(*image))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))
def invert(image):
return [[invert_pixel(pixel) for pixel in row] for row in image]
def invert_pixel(pixel):
return tuple(255 - intensity for intensity in pixel)
def lighten(image, coefficient):
return [
[lighten_pixel(pixel, coefficient) for pixel in row] for row in image
]
def lighten_pixel(pixel, coefficient):
return tuple(
int(intensity + coefficient*(255 - intensity)) for intensity in pixel
)
def darken(image, coefficient):
return [
[darken_pixel(pixel, coefficient) for pixel in row] for row in image
]
def darken_pixel(pixel, coefficient):
return tuple(
int(intensity - coefficient*(intensity - 0)) for intensity in pixel
)
def create_histogram(image):
histogram = {
'red': defaultdict(lambda: 0),
'green': defaultdict(lambda: 0),
'blue': defaultdict(lambda: 0)
}
for row in image:
for pixel in row:
histogram['red'][pixel[0]] += 1
histogram['green'][pixel[1]] += 1
histogram['blue'][pixel[2]] += 1
return histogram

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

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

OK

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

Христо обнови решението на 14.03.2016 16:50 (преди над 5 години)

+def rotate_left(image):
+ return list(zip(*image))[::-1]
+
+
+def rotate_right(image):
+ return list(zip(*image[::-1]))
+
+
+def invert(image):
+ return [[invert_pixel(pixel) for pixel in row] for row in image]
+
+
+def invert_pixel(pixel):
+ return tuple(255 - intensity for intensity in pixel)
+
+
+def lighten(image, coefficient):
+ return [
+ [lighten_pixel(pixel, coefficient) for pixel in row] for row in image
+ ]
+
+
+def lighten_pixel(pixel, coefficient):
+ return tuple(
+ int(intensity + coefficient*(255 - intensity)) for intensity in pixel
+ )
+
+
+def darken(image, coefficient):
+ return [
+ [darken_pixel(pixel, coefficient) for pixel in row] for row in image
+ ]
+
+
+def darken_pixel(pixel, coefficient):
+ return tuple(
+ int(intensity - coefficient*(intensity - 0)) for intensity in pixel
+ )

Христо обнови решението на 14.03.2016 16:56 (преди над 5 години)

+from collections import defaultdict
+
+
def rotate_left(image):
return list(zip(*image))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))
def invert(image):
return [[invert_pixel(pixel) for pixel in row] for row in image]
def invert_pixel(pixel):
return tuple(255 - intensity for intensity in pixel)
def lighten(image, coefficient):
return [
[lighten_pixel(pixel, coefficient) for pixel in row] for row in image
]
def lighten_pixel(pixel, coefficient):
return tuple(
int(intensity + coefficient*(255 - intensity)) for intensity in pixel
)
def darken(image, coefficient):
return [
[darken_pixel(pixel, coefficient) for pixel in row] for row in image
]
def darken_pixel(pixel, coefficient):
return tuple(
int(intensity - coefficient*(intensity - 0)) for intensity in pixel
- )
+ )
+
+
+def create_histogram(image):
+ histogram = {
+ 'red': defaultdict(lambda: 0),
+ 'green': defaultdict(lambda: 0),
+ 'blue': defaultdict(lambda: 0)
+ }
+
+ for row in image:
+ for pixel in row:
+ for red, green, blue in pixel:
+ histogram['red'][pixel[red]] += 1
+ histogram['green'][pixel[green]] += 1
+ histogram['blue'][pixel[blue]] += 1
+
+ return histogram

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

from collections import defaultdict
def rotate_left(image):
return list(zip(*image))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))
def invert(image):
return [[invert_pixel(pixel) for pixel in row] for row in image]
def invert_pixel(pixel):
return tuple(255 - intensity for intensity in pixel)
def lighten(image, coefficient):
return [
[lighten_pixel(pixel, coefficient) for pixel in row] for row in image
]
def lighten_pixel(pixel, coefficient):
return tuple(
int(intensity + coefficient*(255 - intensity)) for intensity in pixel
)
def darken(image, coefficient):
return [
[darken_pixel(pixel, coefficient) for pixel in row] for row in image
]
def darken_pixel(pixel, coefficient):
return tuple(
int(intensity - coefficient*(intensity - 0)) for intensity in pixel
)
def create_histogram(image):
histogram = {
'red': defaultdict(lambda: 0),
'green': defaultdict(lambda: 0),
'blue': defaultdict(lambda: 0)
}
for row in image:
for pixel in row:
- for red, green, blue in pixel:
- histogram['red'][pixel[red]] += 1
- histogram['green'][pixel[green]] += 1
- histogram['blue'][pixel[blue]] += 1
+ histogram['red'][pixel[0]] += 1
+ histogram['green'][pixel[1]] += 1
+ histogram['blue'][pixel[2]] += 1
return histogram