commit ad34602885afb07b313d51eca81fa0169993bf78 Author: Kacper Donat Date: Sun Apr 1 12:40:02 2018 +0200 initial mariusz diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..26e2d8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +.idea +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### own +damaged_* +ok_* diff --git a/decals/1.png b/decals/1.png new file mode 100644 index 0000000..8cad738 Binary files /dev/null and b/decals/1.png differ diff --git a/decals/2.png b/decals/2.png new file mode 100644 index 0000000..e639a14 Binary files /dev/null and b/decals/2.png differ diff --git a/decals/3.png b/decals/3.png new file mode 100644 index 0000000..d278fb6 Binary files /dev/null and b/decals/3.png differ diff --git a/decals/4.png b/decals/4.png new file mode 100644 index 0000000..3e9468c Binary files /dev/null and b/decals/4.png differ diff --git a/decals/5.png b/decals/5.png new file mode 100644 index 0000000..cd9395a Binary files /dev/null and b/decals/5.png differ diff --git a/decals/6.png b/decals/6.png new file mode 100644 index 0000000..e3fa5f8 Binary files /dev/null and b/decals/6.png differ diff --git a/decals/7.png b/decals/7.png new file mode 100644 index 0000000..e45a17f Binary files /dev/null and b/decals/7.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c150495 Binary files /dev/null and b/requirements.txt differ diff --git a/test.jpg b/test.jpg new file mode 100644 index 0000000..c829b8e Binary files /dev/null and b/test.jpg differ diff --git a/uss-mariusz.py b/uss-mariusz.py new file mode 100644 index 0000000..747f618 --- /dev/null +++ b/uss-mariusz.py @@ -0,0 +1,85 @@ +from random import random, choice +from PIL import Image, ImageFilter +from functools import reduce + +import argparse +import os + +def color_ramp(white=(255, 255, 255), black=(0, 0, 0)): + wr, wg, wb = white + br, bg, bb = black + + colors = [[br + (wr - br) * i / 255, bg + (wg - bg) * i / 255, bb + (wb - bb) * i / 255] for i in range(255)] + + return list(map(int, reduce(list.__add__, colors))) + + +sepia = color_ramp((255 - int(random()*25), 230 + int(random()*25), 179+int(random()*25))) + +decals = [os.path.join("decals", f) for f in os.listdir("decals") if os.path.isfile(os.path.join("decals", f))] + + +def clamp(x, value, y): + return max(x, min(value, y)) + + +def add_decal(image, decal): + decal = Image.open(decal) + w, h = image.size + + scale = .5 + random() + scale = scale * min(w/decal.size[0], 1) + + decal = decal.rotate(random() * 360, expand=True) + decal = decal.resize(map(int, (scale * decal.size[0], scale * decal.size[1])), Image.ANTIALIAS) + + dw, dh = decal.size + pos = tuple(map(int, (random() * w - .5 * dw, random() * h - .5 * dh))) + + image.paste(decal, pos, decal) + + +def add_noise(image, level): + data = image.getdata() + + def noise(t): + w = int(random() * 255 * level) + r, g, b, a = t + + return clamp(0, r - w, 255), clamp(0, g - w, 255), clamp(0, b - w, 255), a + + data = list(map(noise, data)) + image.putdata(data) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Damages image") + parser.add_argument('input', help='Image to damage', type=str) + parser.add_argument('output', help='Output image name', type=str, nargs='?') + parser.add_argument('damaged', help='Output damaged image name', type=str, nargs='?') + + parser.add_argument('-d', help='Decals count', type=int, default=8, dest="decals") + parser.add_argument('-n', help='Noise level', type=float, default=.4, dest="noise") + + args = parser.parse_args() + + if args.output is None: + dir, name = os.path.split(args.input) + args.output = os.path.join(dir, "ok_" + name) + + if args.damaged is None: + dir, name = os.path.split(args.input) + args.damaged = os.path.join(dir, "damaged_" + name) + + im = Image.open(args.input) + im = im.convert("L") + im.putpalette(sepia) + im = im.convert("RGBA") + + im.convert("RGB").save(args.output) + add_noise(im, args.noise) + for _ in range(args.decals): + add_decal(im, choice(decals)) + + im = im.filter(ImageFilter.GaussianBlur(1.5)) + im.convert("RGB").save(args.damaged)