Verified Commit 0b1a9db8 authored by Hugo Kerstens's avatar Hugo Kerstens
Browse files

Remove notebook

parent 15bb4d7b
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from zesje.factory import create_app\n",
"from zesje.image_extraction import extract_images_from_file as extract\n",
"\n",
"from pikepdf import PdfError\n",
"\n",
"app = create_app()\n",
"app.app_context().push()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1/3] ['Test_1-1 (7).zip', '256x256/hp_logo.png']\n",
"\t<PIL.Image.Image image mode=RGB size=256x256 at 0x7F4F971FA310>\n",
"[2/3] ['Test_1-1 (7).zip', '256x256/logo.png']\n",
"\t<PIL.Image.Image image mode=RGB size=256x256 at 0x7F4F9717B850>\n",
"[3/5] ['Test_1-1 (7).zip', 'Test_1-1 (6).pdf', 1]\n",
"\t<PIL.Image.Image image mode=RGB size=2481x3508 at 0x7F4F9718A7F0>\n",
"[4/5] ['Test_1-1 (7).zip', 'Test_1-1 (6).pdf', 1]\n",
"\t<PIL.Image.Image image mode=RGB size=2481x3508 at 0x7F4F9718AFD0>\n",
"[5/7] ['Test_1-1 (7).zip', 'Test_flatten.pdf', 1]\n",
"\t<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2481x3508 at 0x7F4F971225E0>\n",
"[6/7] ['Test_1-1 (7).zip', 'Test_flatten.pdf', 1]\n",
"\t<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2481x3508 at 0x7F4F97122730>\n",
"[7/7] ['Test_1-1 (7).zip', 'newplot.png']\n",
"\t<PIL.Image.Image image mode=RGB size=700x450 at 0x7F4F9718A0A0>\n"
]
}
],
"source": [
"for image, path, number, total in extract('/home/hugo/Downloads/Test_1-1 (7).zip', ['Test_1-1 (7).zip']):\n",
" print(f'[{number}/{total}] {path}')\n",
" print(f'\\t{image}')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "extract_images_from_file() missing 1 required positional argument: 'file_info'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-f60373259533>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtotal\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mextract\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/home/hugo/Downloads/Test_flatten.pdf'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf'[{number}/{total}] {path}'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf'\\t{image}'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: extract_images_from_file() missing 1 required positional argument: 'file_info'"
]
}
],
"source": [
"for image, path, number, total in extract('/home/hugo/Downloads/Test_flatten.pdf'):\n",
" print(f'[{number}/{total}] {path}')\n",
" print(f'\\t{image}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"encoded = Path('/home/hugo/Downloads/rle_8.hex').read_bytes()[1:-1]\n",
"encoded = bytearray(encoded)\n",
"width = 595\n",
"height = 842\n",
"bits = 8"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def _get8bitMap(encodedImage):\n",
" imgMap = \"\"\n",
" newEncodedImage = list(encodedImage)\n",
"\n",
" I = range(0, len(newEncodedImage), 9)\n",
"\n",
" for i in I:\n",
" imgMap += '{0:08b}'.format(newEncodedImage[i])\n",
"\n",
" for i in sorted(list(I), reverse = True):\n",
" del newEncodedImage[i]\n",
"\n",
" return (imgMap, newEncodedImage)\n",
"\n",
"def _decodeImage8bit(encodedImage, width, height, scanning):\n",
" decodedImage = []\n",
"\n",
" imgMap, encImg = _get8bitMap(encodedImage)\n",
"\n",
" for index, i in enumerate(imgMap):\n",
" if i == '1' and encImg[index] == 0:\n",
" break\n",
"\n",
" if i == '1':\n",
" decodedImage.extend([encImg[index + 1]] * encImg[index])\n",
" elif imgMap[index - 1] != '1' or index == 0:\n",
" decodedImage.append(encImg[index])\n",
"\n",
" return decodedImage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"_decodeImage8bit(encoded, width, height, None)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{}\n",
"{'test': 1}\n"
]
}
],
"source": [
"def a(b=dict()):\n",
" return b\n",
"\n",
"c = a()\n",
"print(c)\n",
"c['test'] = 1\n",
"c = a()\n",
"print(c)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{}\n",
"{'test': 1}\n"
]
},
{
"data": {
"text/plain": [
"{'test': 1}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c = a()\n",
"c['test'] = 1\n",
"a()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.6.7 64-bit ('zesje-dev': conda)",
"language": "python",
"name": "python36764bitzesjedevconda732a4d5eed6f4d07be5e8bdbe45b0dc3"
},
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment