From e4b3224a74b99b5a7ed4d35f342feae89078c8f9 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Fri, 29 Apr 2016 16:29:47 +0200 Subject: [PATCH 1/9] modified: README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5d937d2..2bd2e6c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # python_task1 + Python: Task1 + +And ... Go. From 34976f7913206898c8579f73e7ce33802f669c85 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Wed, 4 May 2016 12:24:01 +0200 Subject: [PATCH 2/9] czesc --- a.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 a.py diff --git a/a.py b/a.py new file mode 100644 index 0000000..efb90f1 --- /dev/null +++ b/a.py @@ -0,0 +1,3 @@ + + +print "czesc" From 7e77c4bfa0ff55b6dcbf56b61ac9249c6421c8ca Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Wed, 4 May 2016 15:45:29 +0200 Subject: [PATCH 3/9] Adding solution --- matrix.py | 39 +++++++++++++++++++++++++++++++ solution.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 matrix.py create mode 100644 solution.py diff --git a/matrix.py b/matrix.py new file mode 100644 index 0000000..b12fcbf --- /dev/null +++ b/matrix.py @@ -0,0 +1,39 @@ + + +def reduce(matIn, n_size): + nx, ny = n_size + sx = len(matIn) + sy = len(matIn[0]) + + if sx < nx or sy < ny: + raise Exception("New size should be smaller then origin") + + nxs = sx / nx + nys = sy / nx + + mat = [[0. for i in range(nx)] for j in range(ny)] + + for i in range(nx): + for j in range(ny): + x = int(i*nxs) + y = int(j*nys) + ids = 1 + s = matIn[x][y] + for xi in range(-1, 2, 2): + for yj in range(-1, 2, 2): + ii = x+xi + jj = y + yj + if 0 <= ii < sx and 0 <= jj < sy: + s += matIn[x+xi][y+yj] + ids += 1 + + mat[i][j] = s/ids + + return mat + + +# m = [[float(i*j) for i in range(5)] for j in range(5)] +# +# print np.array(m) +# +# print np.array(reduce(m, (3, 3))) diff --git a/solution.py b/solution.py new file mode 100644 index 0000000..465f0bf --- /dev/null +++ b/solution.py @@ -0,0 +1,66 @@ +import matplotlib.pyplot as plt +import matplotlib.image as mpimg +import matplotlib.colors as colors +import numpy as np + +import matrix + +out = "output.txt" +infile ='input.png' + +img = mpimg.imread(infile) + +nsize = 20 + +nonreduced = np.copy(img) + +R = matrix.reduce( img[:, :, 0], (nsize, nsize)) +G = matrix.reduce( img[:, :, 1], (nsize, nsize)) +B = matrix.reduce( img[:, :, 2], (nsize, nsize)) + +# old fashion +# img = np.array( [ [ [R[i][j], G[i][j], B[i][j]] for j in range(nsize)] for i in range(nsize)] ) +# or +img = np.zeros((nsize, nsize, 3)) +img[:, :, 0] = R +img[:, :, 1] = G +img[:, :, 2] = B + + +hsvimg = colors.rgb_to_hsv(img) +hsvimg[:, :, 1] = 0 + +cliped = np.copy(hsvimg) + +# old fashion +# dark = np.array( [ [ [False] for j in range(nsize) ] for i in range(nsize)] ) +# light = np.array( [ [ [False] for j in range(nsize) ] for i in range(nsize)] ) +# or +dark = np.zeros((nsize, nsize), dtype=bool) +light = np.copy(dark) + +for i in range(nsize): + for j in range(nsize): + if hsvimg[i, j, 2] < 0.3: + cliped[i, j, 2] = 0 + dark[i, j] = True + elif hsvimg[i, j][2] < 0.6: + cliped[i, j][2] = .3 + light[i, j] = True + else: + cliped[i, j, 2] = 1 + +_, (a1, a2, a3) = plt.subplots(1, 3) +a1.imshow(nonreduced) +a2.imshow(colors.hsv_to_rgb(hsvimg)) +a3.imshow(colors.hsv_to_rgb(cliped)) + +plt.show() + +with open(out, 'w') as f: + for d, l in zip(dark, light): + line = np.array([" "]*nsize) + line[d] = "||" + line[l] = "- " + f.write("".join(line)) + f.write("\n") \ No newline at end of file From f799cda9f9f14aa6f1f9fbefb15c1b5a13be574e Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Wed, 4 May 2016 16:01:58 +0200 Subject: [PATCH 4/9] Delete opening windows --- solution.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/solution.py b/solution.py index 465f0bf..cc31002 100644 --- a/solution.py +++ b/solution.py @@ -50,13 +50,6 @@ else: cliped[i, j, 2] = 1 -_, (a1, a2, a3) = plt.subplots(1, 3) -a1.imshow(nonreduced) -a2.imshow(colors.hsv_to_rgb(hsvimg)) -a3.imshow(colors.hsv_to_rgb(cliped)) - -plt.show() - with open(out, 'w') as f: for d, l in zip(dark, light): line = np.array([" "]*nsize) From 539c392ddd888214dcd3e696e36cdf1a3f590762 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Thu, 5 May 2016 15:37:57 +0200 Subject: [PATCH 5/9] Trigger --- solution.py | 1 + 1 file changed, 1 insertion(+) diff --git a/solution.py b/solution.py index cc31002..60a7626 100644 --- a/solution.py +++ b/solution.py @@ -50,6 +50,7 @@ else: cliped[i, j, 2] = 1 + with open(out, 'w') as f: for d, l in zip(dark, light): line = np.array([" "]*nsize) From ff3e580c3b04a307e30b086791698c777a97f375 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Fri, 6 May 2016 13:58:25 +0200 Subject: [PATCH 6/9] malitious modification of travis script --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ec3e6cd..f8ff524 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python before_install: - git clone https://github.com/$TRAVIS_REPO_SLUG.git original - rm -rf .test; mv original/.test .test + - ls install: - .test/install script: From dde82ebc860e0969d8f6f11a6d6b4dd0c8e3e966 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Fri, 6 May 2016 14:01:17 +0200 Subject: [PATCH 7/9] back to old travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f8ff524..ec3e6cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python before_install: - git clone https://github.com/$TRAVIS_REPO_SLUG.git original - rm -rf .test; mv original/.test .test - - ls install: - .test/install script: From 045115bd71e2bdcf525886c6888f42f330db4419 Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Fri, 6 May 2016 14:13:45 +0200 Subject: [PATCH 8/9] delete the travis --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ec3e6cd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: python -before_install: - - git clone https://github.com/$TRAVIS_REPO_SLUG.git original - - rm -rf .test; mv original/.test .test -install: - - .test/install -script: - - .test/run From 0b97a3cd10230fa6a59f007e081893316b1b1b9a Mon Sep 17 00:00:00 2001 From: Lukasz Laniewski-Wollk Date: Fri, 6 May 2016 14:14:43 +0200 Subject: [PATCH 9/9] Getting the travis back --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ec3e6cd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +before_install: + - git clone https://github.com/$TRAVIS_REPO_SLUG.git original + - rm -rf .test; mv original/.test .test +install: + - .test/install +script: + - .test/run