Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Réouven ASSOULY
zesje
Commits
0b1a9db8
Verified
Commit
0b1a9db8
authored
Jun 08, 2020
by
Hugo Kerstens
Browse files
Remove notebook
parent
15bb4d7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Untitled.ipynb
deleted
100644 → 0
View file @
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
}
%% Cell type:code id: tags:
```
python
from
zesje.factory
import
create_app
from
zesje.image_extraction
import
extract_images_from_file
as
extract
from
pikepdf
import
PdfError
app
=
create_app
()
app
.
app_context
().
push
()
```
%% Cell type:code id: tags:
```
python
for
image
,
path
,
number
,
total
in
extract
(
'/home/hugo/Downloads/Test_1-1 (7).zip'
,
[
'Test_1-1 (7).zip'
]):
print
(
f
'[
{
number
}
/
{
total
}
]
{
path
}
'
)
print
(
f
'
\t
{
image
}
'
)
```
%% Output
[1/3] ['Test_1-1 (7).zip', '256x256/hp_logo.png']
<PIL.Image.Image image mode=RGB size=256x256 at 0x7F4F971FA310>
[2/3] ['Test_1-1 (7).zip', '256x256/logo.png']
<PIL.Image.Image image mode=RGB size=256x256 at 0x7F4F9717B850>
[3/5] ['Test_1-1 (7).zip', 'Test_1-1 (6).pdf', 1]
<PIL.Image.Image image mode=RGB size=2481x3508 at 0x7F4F9718A7F0>
[4/5] ['Test_1-1 (7).zip', 'Test_1-1 (6).pdf', 1]
<PIL.Image.Image image mode=RGB size=2481x3508 at 0x7F4F9718AFD0>
[5/7] ['Test_1-1 (7).zip', 'Test_flatten.pdf', 1]
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2481x3508 at 0x7F4F971225E0>
[6/7] ['Test_1-1 (7).zip', 'Test_flatten.pdf', 1]
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=2481x3508 at 0x7F4F97122730>
[7/7] ['Test_1-1 (7).zip', 'newplot.png']
<PIL.Image.Image image mode=RGB size=700x450 at 0x7F4F9718A0A0>
%% Cell type:code id: tags:
```
python
for
image
,
path
,
number
,
total
in
extract
(
'/home/hugo/Downloads/Test_flatten.pdf'
):
print
(
f
'[
{
number
}
/
{
total
}
]
{
path
}
'
)
print
(
f
'
\t
{
image
}
'
)
```
%% Output
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-f60373259533> in <module>
----> 1 for image, path, number, total in extract('/home/hugo/Downloads/Test_flatten.pdf'):
2 print(f'[{number}/{total}] {path}')
3 print(f'\t{image}')
TypeError: extract_images_from_file() missing 1 required positional argument: 'file_info'
%% Cell type:code id: tags:
```
python
from
pathlib
import
Path
```
%% Cell type:code id: tags:
```
python
encoded
=
Path
(
'/home/hugo/Downloads/rle_8.hex'
).
read_bytes
()[
1
:
-
1
]
encoded
=
bytearray
(
encoded
)
width
=
595
height
=
842
bits
=
8
```
%% Cell type:code id: tags:
```
python
def
_get8bitMap
(
encodedImage
):
imgMap
=
""
newEncodedImage
=
list
(
encodedImage
)
I
=
range
(
0
,
len
(
newEncodedImage
),
9
)
for
i
in
I
:
imgMap
+=
'{0:08b}'
.
format
(
newEncodedImage
[
i
])
for
i
in
sorted
(
list
(
I
),
reverse
=
True
):
del
newEncodedImage
[
i
]
return
(
imgMap
,
newEncodedImage
)
def
_decodeImage8bit
(
encodedImage
,
width
,
height
,
scanning
):
decodedImage
=
[]
imgMap
,
encImg
=
_get8bitMap
(
encodedImage
)
for
index
,
i
in
enumerate
(
imgMap
):
if
i
==
'1'
and
encImg
[
index
]
==
0
:
break
if
i
==
'1'
:
decodedImage
.
extend
([
encImg
[
index
+
1
]]
*
encImg
[
index
])
elif
imgMap
[
index
-
1
]
!=
'1'
or
index
==
0
:
decodedImage
.
append
(
encImg
[
index
])
return
decodedImage
```
%% Cell type:code id: tags:
```
python
_decodeImage8bit
(
encoded
,
width
,
height
,
None
)
```
%% Cell type:code id: tags:
```
python
def
a
(
b
=
dict
()):
return
b
c
=
a
()
print
(
c
)
c
[
'test'
]
=
1
c
=
a
()
print
(
c
)
```
%% Output
{}
{'test': 1}
%% Cell type:code id: tags:
```
python
c
=
a
()
c
[
'test'
]
=
1
a
()
```
%% Output
{}
{'test': 1}
{'test': 1}
%% Cell type:code id: tags:
```
python
```
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment