145 lines
361 KiB
Plaintext
145 lines
361 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"from lib import plot\n",
|
||
|
"import IPython\n",
|
||
|
"import cv2\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"paper = plot.A6_PORTRAIT"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.image.AxesImage at 0x7f3254dc1130>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAACHCAYAAAAP+QIqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAD/IklEQVR4nOz92a9t25beCf16NcaY9Vpr16c+98aN0naE7UzXQihrEGSCBAgQCCQkP/GAxAMW/wD5hMQLCEukICUkJxIpQEgpJ07SSjJTctoRGeFwRNz6nnuqXa16VqPoBQ+tjz7nWmefe68jrHvD0u7SPmfvOeeo+2i9ta997WsqpcTb8Xa8HW/H2/HP39C/6BN4O96Ot+PteDv+eOOtAX873o634+3453S8NeBvx9vxdrwd/5yOtwb87Xg73o6345/T8daAvx1vx9vxdvxzOt4a8Lfj7Xg73o5/TsefyIArpf4NpdR3lFLfV0r9rX9WJ/V2vB1vx9vxdvz0of64PHCllAG+C/yrwOfAPwT+BymlP/xnd3pvx9vxdrwdb8fXj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1Cdh7wIc3V7gECLN/lVGGCE9o4x9mPIo7wLI549QntfgyPfwY7H3x3biWNoBO4Y5rLP432M+/YeZe0Rtp/Pc/S2Jw3ERLy9vfve5nNM3pP6vuQ9VNPI9YUo9yCEgsXfye8cvbejnfx74d/77ZTSv3D/Xv5JIJQ//vhZE4f6riH/mROUf9Jz+BmP90+TvLwzRo/g/imN+N2dJN0bvNJ7IRtakXDi0YQguPY4wQAVAmo+J00bhgdzUqWJ9mD8o9MMM83th4ZQQ6zECKDEUAKopDA7LaH/JOGnkbAM9K1GBUW
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"img = cv2.imread('data/boltzmann.jpg')\n",
|
||
|
"output_shape = (200, 60)\n",
|
||
|
"\n",
|
||
|
"img = img.dot([0.07, 0.72, 0.21]) / 255\n",
|
||
|
"\n",
|
||
|
"paper_aspect = paper.content_width / paper.content_height\n",
|
||
|
"img_aspect = img.shape[1] / img.shape[0]\n",
|
||
|
"if img_aspect < paper_aspect:\n",
|
||
|
" new_height = round(img.shape[1] / paper_aspect)\n",
|
||
|
" y_offset = (img.shape[0] - new_height) // 2\n",
|
||
|
" img = img[y_offset:y_offset + new_height, :]\n",
|
||
|
"else:\n",
|
||
|
" new_width = round(img.shape[0] * paper_aspect)\n",
|
||
|
" x_offset = (img.shape[1] - new_width) // 2\n",
|
||
|
" img = img[:, x_offset:new_width + x_offset]\n",
|
||
|
"\n",
|
||
|
"img = cv2.resize(img, dsize=output_shape, interpolation=cv2.INTER_CUBIC)\n",
|
||
|
"\n",
|
||
|
"img = img - np.min(img)\n",
|
||
|
"img = 1 - img / np.max(img)\n",
|
||
|
"\n",
|
||
|
"plt.imshow(img[:, :])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/svg+xml": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"297.637795pt\" height=\"419.527559pt\" viewBox=\"0 0 297.637795 419.527559\" version=\"1.1\">\n<g id=\"surface1\">\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 7.999512 7.999512 L 97.000109 7.999512 L 97.000109 140.000412 L 7.999512 140.000412 L 7.999512 7.999512 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(30%,15%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 7.999512 9.100564 L 8.222754 9.100564 L 8.66786 9.09643 L 9.112967 9.095052 L 9.558073 9.095052 L 10.003179 9.100564 L 10.446908 9.104698 L 10.892014 9.093674 L 11.33712 9.112967 L 11.782227 9.108832 L 12.227333 9.107454 L 12.672439 9.099186 L 13.117546 9.100564 L 14.007758 9.100564 L 14.452865 9.101942 L 14.897971 9.093674 L 15.343077 9.099186 L 15.788184 9.097808 L 16.231912 9.09643 L 16.677018 9.092296 L 17.122125 9.107454 L 17.567231 9.10332 L 18.012337 9.097808 L 18.457444 9.099186 L 18.90255 9.104698 L 19.347656 9.090918 L 19.792763 9.101942 L 20.237869 9.106076 L 20.682975 9.101942 L 21.128082 9.119857 L 21.573188 9.111589 L 22.016916 9.10332 L 22.462023 9.108832 L 22.907129 9.10332 L 23.352235 9.115723 L 23.797342 9.08954 L 24.242448 9.108832 L 24.687554 9.097808 L 25.132661 9.10332 L 25.577767 9.095052 L 26.022873 9.101942 L 26.46798 9.092296 L 26.913086 9.104698 L 27.356814 9.104698 L 27.801921 9.090918 L 28.247027 9.09643 L 28.692133 9.100564 L 29.13724 9.10332 L 29.582346 9.099186 L 30.027452 9.088162 L 30.472559 9.119857 L 30.917665 9.110211 L 31.362771 9.093674 L 31.807878 9.092296 L 32.252984 9.09643 L 32.69809 9.092296 L 33.141819 9.085406 L 33.586925 9.110211 L 34.032031 9.09643 L 34.477138 9.085406 L 34.922244 9.117101 L 35.36735 9.107454 L 35.812457 9.100564 L 36.257563 9.101942 L 36.702669 9.099186 L 37.147776 9.100564 L 37.592882 9.093674 L 38.037988 9.101942 L 38.483095 9.108832 L 38.926823 9.110211 L 39.371929 9.084028 L 39.817036 9.104698 L 40.262142 9.101942 L 40.707248 9.108832 L 41.152355 9.141905 L 41.597461 9.114345 L 42.042567 9.060601 L 42.487674 9.125369 L 42.93278 9.123991 L 43.377886 9.104698 L 43.822993 9.112967 L 44.268099 9.104698 L 44.711827 9.09643 L 45.156934 9.106076 L 45.60204 9.084028 L 46.047146 9.106076 L 46.492253 9.125369 L 46.937359 9.086784 L 47.382465 9.099186 L 47.827572 9.057845 L 48.272678 9.107454 L 48.717784 9.079894 L 49.162891 9.088162 L 49.607997 9.119857 L 50.053103 9.107454 L 50.496832 9.10332 L 50.941938 9.068869 L 51.387044 9.111589 L 51.832151 9.099186 L 52.277257 9.104698 L 52.722363 9.086784 L 53.16747 9.090918 L 53.612576 9.111589 L 54.057682 9.119857 L 54.502789 9.117101 L 54.947895 9.10332 L 55.393001 9.136393 L 55.838108 9.068869 L 56.281836 9.141905 L 56.726942 9.106076 L 57.172049 9.08954 L 57.617155 9.107454 L 58.062261 9.165332 L 58.507368 9.118479 L 59.842687 9.118479 L 60.287793 9.104698 L 60.732899 9.079894 L 61.178006 9.099186 L 61.623112 9.016504 L 62.06684 9.097808 L 62.511947 9.10332 L 62.957053 9.09643 L 63.402159 9.104698 L 63.847266 9.115723 L 64.292372 9.110211 L 64.737478 9.099186 L 65.182585 9.129503 L 65.627691 9.10332 L 66.072797 9.112967 L 66.517904 9.110211 L 66.96301 9.100564 L 67.408116 9.115723 L 67.851845 9.077138 L 68.296951 9.09643 L 68.742057 9.101942 L 69.187164 9.099186 L 69.63227 9.100564 L 70.077376 9.095052 L 70.522483 9.093674 L 70.967589 9.067491 L 71.412695 9.123991 L 71.857802 9.110211 L 72.302908 9.121235 L 72.748014 9.10332 L 73.193121 9.10332 L 73.636849 9.09643 L 74.081955 9.111589 L 74.527062 9.104698 L 74.972168 9.088162 L 75.417274 9.088162 L 75.862381 9.097808 L 76.307487 9.126747 L 76.752593 9.090918 L 77.1977 9.101942 L 77.642806 9.084028 L 78.087912 9.111589 L 78.533019 9.100564 L 78.978125 9.09643 L 79.421853 9.090918 L 79.86696 9.115723 L 80.312066 9.097808 L 80.757172 9.111589 L 81.202279 9.097808 L 81.647385 9.099
|
||
|
"text/plain": [
|
||
|
"<IPython.core.display.SVG object>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"p_svg = plot.SVGPlotter('plots/portrait.svg', paper)\n",
|
||
|
"p_hpgl = plot.HPGLPlotter(paper, 'plots/portrait_{index}.hpgl')\n",
|
||
|
"plotter = plot.MultiPlotter()\n",
|
||
|
"plotter.register_plotter(p_svg)\n",
|
||
|
"plotter.register_plotter(p_hpgl)\n",
|
||
|
"\n",
|
||
|
"plotter.move_to(paper.bottom_left())\n",
|
||
|
"plotter.line_to(paper.bottom_right())\n",
|
||
|
"plotter.line_to(paper.top_right())\n",
|
||
|
"plotter.line_to(paper.top_left())\n",
|
||
|
"plotter.line_to(paper.bottom_left())\n",
|
||
|
"\n",
|
||
|
"plotter.add_layer([0.3, 0.15, 0, 0.5])\n",
|
||
|
"\n",
|
||
|
"noise_img = np.random.normal(size=img.shape) * img * 0.7\n",
|
||
|
"\n",
|
||
|
"for yi in range(img.shape[0]):\n",
|
||
|
" y = paper.top() + (yi + 0.5) * (paper.content_height / img.shape[0])\n",
|
||
|
" plotter.move_to((paper.left(), y))\n",
|
||
|
" for xi in range(img.shape[1]):\n",
|
||
|
" x = paper.left() + (xi + 0.5) * (paper.content_width / img.shape[1])\n",
|
||
|
" plotter.line_to((x, y + noise_img[yi, xi]))\n",
|
||
|
"\n",
|
||
|
"plotter.finalise()\n",
|
||
|
"IPython.display.SVG(filename=p_svg.file_name)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3.9.15 64-bit",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.9.15"
|
||
|
},
|
||
|
"orig_nbformat": 4,
|
||
|
"vscode": {
|
||
|
"interpreter": {
|
||
|
"hash": "1dc4d77b1edb83bef89f833b7ed5251134c6a4899ef5e2c90c44e9927b4ae63a"
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|