Last active
June 4, 2020 13:51
-
-
Save maschere/6c789d70bbdaed2d89e1742f9d50a508 to your computer and use it in GitHub Desktop.
lowpolypy.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "lowpolypy.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"toc_visible": true, | |
"authorship_tag": "ABX9TyOPEXI1y96rAsxvE5J/3e20", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/maschere/6c789d70bbdaed2d89e1742f9d50a508/lowpolypy.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "lv6TJQvp1-jT", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Setup environment\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "0IVWk1L3u5Ex", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"!git clone https://github.com/tasercake/lowpolypy --depth=1\n", | |
"%cd lowpolypy" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "_auTNwZfvjZR", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"pip install -r requirements.txt" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "b4vzv4DUwyUi", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"from lowpolypy import run\n", | |
"from PIL import Image\n", | |
"from google.colab import files\n", | |
"from glob import glob\n" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "G1geg0aM2Ghh", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# select and process image" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "M68-r3wC2tvr", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### choose image by url" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "cP557BeC2TFj", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"!rm -rf /image-download\n", | |
"!wget -P /image-download 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Mona_Lisa-restored.jpg/1200px-Mona_Lisa-restored.jpg'\n", | |
"img_file = glob(\"/image-download/*\")[0]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zrjs39ji20IQ", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### upload an image" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bfSh30Ng24oh", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"img_file = list(files.upload().keys())[0]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ov9zt85m5h-o", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### process it" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ag8Q411sy3ws", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"f = run.run({'mode': 'run', 'image_paths': [img_file],\n", | |
" 'output_dir': None, 'longest_edge': 800,\n", | |
" 'output_size': 2500, 'polygon_method': 'delaunay',\n", | |
" 'num_canny_points': 2500, 'num_laplace_points': 0,\n", | |
" 'num_random_points': 0, 'canny_low_threshold': 150,\n", | |
" 'canny_high_threshold': 200,\n", | |
" 'random_replace_ratio': 0.01, 'jiggle_ratio': 0.003,\n", | |
" 'gradient': 'none', 'post_saturation': 0.1, 'post_brightness': 0.0,\n", | |
" 'post_contrast': 0.25, 'visualize_canny': False,\n", | |
" 'visualize_laplace': False, 'visualize_points': False})" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "PdOCecUD2Nyp", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Show output" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "SW6BIaSu0Bwt", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"Image.open((list(f.keys())[0]))" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Thank you.
And yes, I fixed the upload code
Would it be alright if I linked to this gist from the main repo's Readme? That would help more people get started quickly.
Thanks again for putting this notebook together :)
Absolutely, go ahead!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic work!
I faced an issue when trying to upload images.
Should it be
files.upload().keys()
instead of.values()
?