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

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

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

Резултати

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

Код

from collections import Counter
import copy
def proces_image(image, func):
result = copy.deepcopy(image)
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n * (255 - color)))
def darken(image, n):
return proces_image(image, lambda color:
int(color - n * (255 - color)))
def invert(image):
return proces_image(image, lambda color:
255 - color)
def create_histogram(image):
histogram = {}
for i, color in enumerate(['red', 'green', 'blue']):
histogram[color] = dict(Counter([pixel[i]
for row in image for pixel in row]))
return histogram
def rotate_left(image):
return list(zip(*image[:]))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))

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

..FF........
======================================================================
FAIL: test_darken (test.TestImages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 127 not less than or equal to 1

======================================================================
FAIL: test_darken_rectangle (test.TestImages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 28 not less than or equal to 1

----------------------------------------------------------------------
Ran 12 tests in 0.088s

FAILED (failures=2)

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

Христо обнови решението на 12.03.2016 21:48 (преди над 5 години)

+def proces_image(image, func):
+ result = image[:]
+ for i, row in enumerate(result):
+ for j, pixel in enumerate(row):
+ result[i][j] = ()
+ for color in pixel:
+ result[i][j] += (func(color),)
+ return result
+
+def lighten(image, n):
+ return proces_image(image, lambda color:
+ int(color + n*(255-color)))
+
+def darken(image, n):
+ return proces_image(image, lambda color:
+ int(color - n*(255-color)))
+
+def invert(image):
+ return proces_image(image, lambda color:
+ 255-color)
+
+def create_histogram(image):
+ colors = ['red', 'green', 'blue'];
+ histogram = {}
+
+ for row in image:
+ for pixel in row:
+ for i, value in enumerate(pixel):
+ color = colors[i]
+ if color in histogram:
+ if value in histogram[color]:
+ histogram[color][value] += 1
+ else:
+ histogram[color][value] = 1
+ else:
+ histogram[color] = {value:1}
+ return histogram
+
+def rotate_left(image):
+ return reversed(list(zip(*image[:])))
+
+def rotate_right(image):
+ return list(zip(*image[::-1]))

Христо обнови решението на 13.03.2016 02:10 (преди над 5 години)

def proces_image(image, func):
result = image[:]
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n*(255-color)))
def darken(image, n):
return proces_image(image, lambda color:
int(color - n*(255-color)))
def invert(image):
return proces_image(image, lambda color:
255-color)
def create_histogram(image):
- colors = ['red', 'green', 'blue'];
- histogram = {}
-
- for row in image:
- for pixel in row:
- for i, value in enumerate(pixel):
- color = colors[i]
- if color in histogram:
- if value in histogram[color]:
- histogram[color][value] += 1
- else:
- histogram[color][value] = 1
- else:
- histogram[color] = {value:1}
+ red = [r for row in image for (r,g,b) in row]
+ green = [g for row in image for (r,g,b) in row]
+ blue = [b for row in image for (r,g,b) in row]
+
+ histogram = {'red': dict(Counter(red)),
+ 'green': dict(Counter(green)),
+ 'blue' : dict(Counter(blue))}
return histogram
def rotate_left(image):
return reversed(list(zip(*image[:])))
def rotate_right(image):
return list(zip(*image[::-1]))

Христо обнови решението на 13.03.2016 14:26 (преди над 5 години)

def proces_image(image, func):
result = image[:]
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n*(255-color)))
def darken(image, n):
return proces_image(image, lambda color:
int(color - n*(255-color)))
def invert(image):
return proces_image(image, lambda color:
255-color)
def create_histogram(image):
- red = [r for row in image for (r,g,b) in row]
- green = [g for row in image for (r,g,b) in row]
- blue = [b for row in image for (r,g,b) in row]
-
- histogram = {'red': dict(Counter(red)),
- 'green': dict(Counter(green)),
- 'blue' : dict(Counter(blue))}
- return histogram
+ raw = [[r for row in image for (r,g,b) in row],
+ [g for row in image for (r,g,b) in row],
+ [b for row in image for (r,g,b) in row]]
+
+ counted = [dict(Counter(color)) for color in raw]
+ colors = ['red', 'green', 'blue']
+
+ return dict(zip(colors, counted))
def rotate_left(image):
return reversed(list(zip(*image[:])))
def rotate_right(image):
return list(zip(*image[::-1]))

Христо обнови решението на 13.03.2016 14:27 (преди над 5 години)

def proces_image(image, func):
result = image[:]
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n*(255-color)))
def darken(image, n):
return proces_image(image, lambda color:
int(color - n*(255-color)))
def invert(image):
return proces_image(image, lambda color:
255-color)
def create_histogram(image):
- raw = [[r for row in image for (r,g,b) in row],
- [g for row in image for (r,g,b) in row],
- [b for row in image for (r,g,b) in row]]
+ raw = [[r for row in image for (r,g,b) in row],
+ [g for row in image for (r,g,b) in row],
+ [b for row in image for (r,g,b) in row]]
- counted = [dict(Counter(color)) for color in raw]
- colors = ['red', 'green', 'blue']
-
- return dict(zip(colors, counted))
+ counted = [dict(Counter(color)) for color in raw]
+ colors = ['red', 'green', 'blue']
+
+ return dict(zip(colors, counted))
def rotate_left(image):
return reversed(list(zip(*image[:])))
def rotate_right(image):
return list(zip(*image[::-1]))

Христо обнови решението на 13.03.2016 14:40 (преди над 5 години)

+from collections import Counter
+
def proces_image(image, func):
- result = image[:]
- for i, row in enumerate(result):
- for j, pixel in enumerate(row):
- result[i][j] = ()
- for color in pixel:
- result[i][j] += (func(color),)
- return result
+ result = image[:]
+ for i, row in enumerate(result):
+ for j, pixel in enumerate(row):
+ result[i][j] = ()
+ for color in pixel:
+ result[i][j] += (func(color),)
+ return result
+
def lighten(image, n):
- return proces_image(image, lambda color:
- int(color + n*(255-color)))
+ return proces_image(image, lambda color:
+ int(color + n * (255 - color)))
+
def darken(image, n):
- return proces_image(image, lambda color:
- int(color - n*(255-color)))
+ return proces_image(image, lambda color:
+ int(color - n * (255 - color)))
+
def invert(image):
- return proces_image(image, lambda color:
- 255-color)
+ return proces_image(image, lambda color:
+ 255 - color)
+
def create_histogram(image):
- raw = [[r for row in image for (r,g,b) in row],
- [g for row in image for (r,g,b) in row],
- [b for row in image for (r,g,b) in row]]
+ raw = [[r for row in image for (r, g, b) in row],
+ [g for row in image for (r, g, b) in row],
+ [b for row in image for (r, g, b) in row]]
- counted = [dict(Counter(color)) for color in raw]
- colors = ['red', 'green', 'blue']
+ counted = [dict(Counter(color)) for color in raw]
+ colors = ['red', 'green', 'blue']
- return dict(zip(colors, counted))
-
+ return dict(zip(colors, counted))
+
+
def rotate_left(image):
- return reversed(list(zip(*image[:])))
+ return reversed(list(zip(*image[:])))
+
def rotate_right(image):
- return list(zip(*image[::-1]))
+ return list(zip(*image[::-1]))

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

from collections import Counter
+import copy
+
def proces_image(image, func):
- result = image[:]
+ result = copy.deepcopy(image)
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n * (255 - color)))
def darken(image, n):
return proces_image(image, lambda color:
int(color - n * (255 - color)))
def invert(image):
return proces_image(image, lambda color:
255 - color)
def create_histogram(image):
raw = [[r for row in image for (r, g, b) in row],
[g for row in image for (r, g, b) in row],
[b for row in image for (r, g, b) in row]]
counted = [dict(Counter(color)) for color in raw]
colors = ['red', 'green', 'blue']
return dict(zip(colors, counted))
def rotate_left(image):
- return reversed(list(zip(*image[:])))
+ return list(zip(*image[:]))[::-1]
def rotate_right(image):
- return list(zip(*image[::-1]))
+ return list(zip(*image[::-1]))

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

from collections import Counter
import copy
def proces_image(image, func):
result = copy.deepcopy(image)
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
-
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n * (255 - color)))
-
def darken(image, n):
return proces_image(image, lambda color:
int(color - n * (255 - color)))
-
def invert(image):
return proces_image(image, lambda color:
255 - color)
-
def create_histogram(image):
- raw = [[r for row in image for (r, g, b) in row],
- [g for row in image for (r, g, b) in row],
- [b for row in image for (r, g, b) in row]]
-
- counted = [dict(Counter(color)) for color in raw]
- colors = ['red', 'green', 'blue']
-
- return dict(zip(colors, counted))
-
+ histogram = {}
+ for i, color in enumerate(['red', 'green', 'blue']):
+ histogram[color] = dict(Counter([pixel[i]
+ for row in image for pixel in row]))
+ return histogram
def rotate_left(image):
return list(zip(*image[:]))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))

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

from collections import Counter
import copy
def proces_image(image, func):
result = copy.deepcopy(image)
for i, row in enumerate(result):
for j, pixel in enumerate(row):
result[i][j] = ()
for color in pixel:
result[i][j] += (func(color),)
return result
+
def lighten(image, n):
return proces_image(image, lambda color:
int(color + n * (255 - color)))
+
def darken(image, n):
return proces_image(image, lambda color:
int(color - n * (255 - color)))
+
def invert(image):
return proces_image(image, lambda color:
255 - color)
+
def create_histogram(image):
histogram = {}
for i, color in enumerate(['red', 'green', 'blue']):
histogram[color] = dict(Counter([pixel[i]
for row in image for pixel in row]))
return histogram
+
def rotate_left(image):
return list(zip(*image[:]))[::-1]
def rotate_right(image):
return list(zip(*image[::-1]))