Решение на Работа с картинки от Теодор Тошков

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

Към профила на Теодор Тошков

Резултати

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

Код

def invert_color(pixel):
return(
255 - pixel[0],
255 - pixel[1],
255 - pixel[2]
)
def invert(picture):
return [[invert_color(pixel) for pixel in row] for row in picture]
def rotate_right(picture):
return [list(x) for x in zip(*picture[::-1])]
def rotate_left(picture):
return [list(x) for x in zip(*picture)][::-1]
def lighten_single(color, factor):
new = color + factor * (255 - color)
if new > 255:
return 255
else:
return int(new)
def lighten_pixel(pixel, factor):
return (
lighten_single(pixel[0], factor),
lighten_single(pixel[1], factor),
lighten_single(pixel[2], factor)
)
def darken_pixel(pixel, factor):
return (
int(pixel[0] * (1 - factor)),
int(pixel[1] * (1 - factor)),
int(pixel[2] * (1 - factor))
)
def lighten(picture, factor):
return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]
def darken(picture, factor):
return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]
def partial_histogram(picture, i):
partial = {}
for row in picture:
for pixel in row:
if pixel[i] in partial:
partial[pixel[i]] = partial[pixel[i]] + 1
else:
partial[pixel[i]] = 1
return partial
def create_histogram(picture):
return {
'red': partial_histogram(picture, 0),
'green': partial_histogram(picture, 1),
'blue': partial_histogram(picture, 2)
}

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

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

OK

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

Теодор обнови решението на 08.03.2016 15:57 (преди над 5 години)

+def invert_color(pixel):
+ return(255 - pixel[0],
+ 255 - pixel[1],
+ 255 - pixel[2])
+
+def invert(picture):
+ return [[invert_color(pixel) for pixel in row] for row in picture]
+
+def rotate_right(picture):
+ return [list(x) for x in zip(*picture[::-1])]
+
+def rotate_left (picture):
+ return [list(x) for x in zip(*picture)][::-1]
+
+def lighten_single (color, factor):
+ new = color + factor * (255 - color)
+ if new > 255 :
+ return 255
+ else :
+ return int(new)
+
+def lighten_pixel (pixel, factor):
+ return (lighten_single(pixel[0], factor),
+ lighten_single(pixel[1], factor),
+ lighten_single(pixel[2], factor) )
+
+def darken_pixel (pixel, factor):
+ return (int(pixel[0] * (1 - factor)),
+ int(pixel[1] * (1 - factor)),
+ int(pixel[2] * (1 - factor)))
+
+def lighten (picture, factor):
+ return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]
+
+def darken (picture, factor):
+ return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]
+
+def partial_histogram(picture, i):
+ partial = {}
+ for row in picture:
+ for pixel in row:
+ if pixel[i] in partial:
+ partial[pixel[i]] = partial[pixel[i]] + 1
+ else:
+ partial[pixel[i]] = 1
+ return partial
+
+def create_histogram(picture):
+ return {'red': partial_histogram(picture, 0),
+ 'green': partial_histogram(picture, 1),
+ 'blue': partial_histogram(picture, 2)}

Теодор обнови решението на 09.03.2016 00:38 (преди над 5 години)

def invert_color(pixel):
- return(255 - pixel[0],
- 255 - pixel[1],
+ return(255 - pixel[0],
+ 255 - pixel[1],
255 - pixel[2])
+
def invert(picture):
- return [[invert_color(pixel) for pixel in row] for row in picture]
+ return [[invert_color(pixel) for pixel in row] for row in picture]
-def rotate_right(picture):
- return [list(x) for x in zip(*picture[::-1])]
-def rotate_left (picture):
- return [list(x) for x in zip(*picture)][::-1]
+def rotate_right(picture):
+ return [list(x) for x in zip(*picture[::-1])]
-def lighten_single (color, factor):
+
+def rotate_left(picture):
+ return [list(x) for x in zip(*picture)][::-1]
+
+
+def lighten_single(color, factor):
new = color + factor * (255 - color)
- if new > 255 :
+ if new > 255:
return 255
- else :
+ else:
return int(new)
-def lighten_pixel (pixel, factor):
- return (lighten_single(pixel[0], factor),
- lighten_single(pixel[1], factor),
- lighten_single(pixel[2], factor) )
-def darken_pixel (pixel, factor):
+def lighten_pixel(pixel, factor):
+ return (lighten_single(pixel[0], factor),
+ lighten_single(pixel[1], factor),
+ lighten_single(pixel[2], factor))
+
+
+def darken_pixel(pixel, factor):
return (int(pixel[0] * (1 - factor)),
int(pixel[1] * (1 - factor)),
int(pixel[2] * (1 - factor)))
-def lighten (picture, factor):
+
+def lighten(picture, factor):
return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]
-def darken (picture, factor):
+
+def darken(picture, factor):
return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]
+
def partial_histogram(picture, i):
- partial = {}
- for row in picture:
- for pixel in row:
- if pixel[i] in partial:
- partial[pixel[i]] = partial[pixel[i]] + 1
- else:
- partial[pixel[i]] = 1
- return partial
+ partial = {}
+ for row in picture:
+ for pixel in row:
+ if pixel[i] in partial:
+ partial[pixel[i]] = partial[pixel[i]] + 1
+ else:
+ partial[pixel[i]] = 1
+ return partial
+
def create_histogram(picture):
return {'red': partial_histogram(picture, 0),
'green': partial_histogram(picture, 1),
'blue': partial_histogram(picture, 2)}

Теодор обнови решението на 11.03.2016 19:31 (преди над 5 години)

def invert_color(pixel):
- return(255 - pixel[0],
- 255 - pixel[1],
- 255 - pixel[2])
+ return(
+ 255 - pixel[0],
+ 255 - pixel[1],
+ 255 - pixel[2]
+ )
def invert(picture):
return [[invert_color(pixel) for pixel in row] for row in picture]
def rotate_right(picture):
return [list(x) for x in zip(*picture[::-1])]
def rotate_left(picture):
return [list(x) for x in zip(*picture)][::-1]
def lighten_single(color, factor):
new = color + factor * (255 - color)
if new > 255:
return 255
else:
return int(new)
def lighten_pixel(pixel, factor):
- return (lighten_single(pixel[0], factor),
- lighten_single(pixel[1], factor),
- lighten_single(pixel[2], factor))
+ return (
+ lighten_single(pixel[0], factor),
+ lighten_single(pixel[1], factor),
+ lighten_single(pixel[2], factor)
+ )
def darken_pixel(pixel, factor):
- return (int(pixel[0] * (1 - factor)),
- int(pixel[1] * (1 - factor)),
- int(pixel[2] * (1 - factor)))
+ return (
+ int(pixel[0] * (1 - factor)),
+ int(pixel[1] * (1 - factor)),
+ int(pixel[2] * (1 - factor))
+ )
def lighten(picture, factor):
return [[lighten_pixel(pixel, factor) for pixel in row] for row in picture]
def darken(picture, factor):
return [[darken_pixel(pixel, factor) for pixel in row] for row in picture]
def partial_histogram(picture, i):
partial = {}
for row in picture:
for pixel in row:
if pixel[i] in partial:
partial[pixel[i]] = partial[pixel[i]] + 1
else:
partial[pixel[i]] = 1
return partial
def create_histogram(picture):
- return {'red': partial_histogram(picture, 0),
- 'green': partial_histogram(picture, 1),
+ return {
- 'blue': partial_histogram(picture, 2)}
+ 'red': partial_histogram(picture, 0),
+ 'green': partial_histogram(picture, 1),
+ 'blue': partial_histogram(picture, 2)
+ }