Commit 02f1db61 authored by Bryce Hepner's avatar Bryce Hepner

Tested out large amount. Works well will same dict

parent abb3eb44
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -260,7 +260,6 @@ ...@@ -260,7 +260,6 @@
" \n", " \n",
" # create a list of huffman table\n", " # create a list of huffman table\n",
" huffman_encoding_list = [huffman_encoding_dict]\n", " huffman_encoding_list = [huffman_encoding_dict]\n",
" print(len(huffman_encoding_list))\n",
" n = len(bins)\n", " n = len(bins)\n",
" \n", " \n",
" # loop through different bins\n", " # loop through different bins\n",
...@@ -311,14 +310,14 @@ ...@@ -311,14 +310,14 @@
" # huffman_encoding_list = list(set(huffman_encoding_list))\n", " # huffman_encoding_list = list(set(huffman_encoding_list))\n",
" diff = np.reshape(diff,(510,638))\n", " diff = np.reshape(diff,(510,638))\n",
" # return the huffman dictionary\n", " # return the huffman dictionary\n",
" print(len(huffman_encoding_list))\n", "\n",
" return huffman_encoding_list, image_array, new_error, diff, boundary, predict, bins, A\n", " return huffman_encoding_list, image_array, new_error, diff, boundary, predict, bins, A\n",
" \n" " \n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -358,7 +357,7 @@ ...@@ -358,7 +357,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -447,7 +446,7 @@ ...@@ -447,7 +446,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -510,14 +509,14 @@ ...@@ -510,14 +509,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1\n", "True\n",
"5\n" "5\n"
] ]
} }
...@@ -525,7 +524,7 @@ ...@@ -525,7 +524,7 @@
"source": [ "source": [
"scenes = file_extractor()\n", "scenes = file_extractor()\n",
"images = image_extractor(scenes)\n", "images = image_extractor(scenes)\n",
"list_dic, image, new_error, diff, bound, predict, bins, A = huffman(images[0], 4, False)\n", "list_dic, image, new_error, diff, bound, predict, bins, A = huffman(images[2], 4, False)\n",
"encoded_string = encoder(new_error, list_dic, diff, bound, bins)\n", "encoded_string = encoder(new_error, list_dic, diff, bound, bins)\n",
"reconstruct_image = decoder(A, encoded_string, list_dic, bins, False)\n", "reconstruct_image = decoder(A, encoded_string, list_dic, bins, False)\n",
"print(np.allclose(image, reconstruct_image))\n", "print(np.allclose(image, reconstruct_image))\n",
...@@ -534,16 +533,16 @@ ...@@ -534,16 +533,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"0.4232928466796875" "0.4246848551432292"
] ]
}, },
"execution_count": 26, "execution_count": 30,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -554,14 +553,14 @@ ...@@ -554,14 +553,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2080618\n" "2087460\n"
] ]
} }
], ],
...@@ -573,7 +572,7 @@ ...@@ -573,7 +572,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -590,14 +589,14 @@ ...@@ -590,14 +589,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2080569\n" "2087411\n"
] ]
} }
], ],
...@@ -607,7 +606,7 @@ ...@@ -607,7 +606,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -633,14 +632,14 @@ ...@@ -633,14 +632,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2080618\n" "2087460\n"
] ]
} }
], ],
...@@ -652,16 +651,16 @@ ...@@ -652,16 +651,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 172, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"0.6058229115470704" "0.607930346608399"
] ]
}, },
"execution_count": 172, "execution_count": 36,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -670,11 +669,67 @@ ...@@ -670,11 +669,67 @@
"(os.path.getsize('MatrixNowString.txt'))/os.path.getsize('images/1626032610_393963/1626032610_393963_0.tiff')" "(os.path.getsize('MatrixNowString.txt'))/os.path.getsize('images/1626032610_393963/1626032610_393963_0.tiff')"
] ]
}, },
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/bryce/git/master/SaveableEncoderDecoder.ipynb Cell 18'\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=1'>2</a>\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m200\u001b[39m):\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=2'>3</a>\u001b[0m list_dic, image, new_error, diff, bound, predict, bins, A \u001b[39m=\u001b[39m huffman(images[i], \u001b[39m4\u001b[39m, \u001b[39mFalse\u001b[39;00m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=3'>4</a>\u001b[0m encoded_string \u001b[39m=\u001b[39m encoder(new_error, list_dic, diff, bound, bins)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=4'>5</a>\u001b[0m \u001b[39m# reconstruct_image = decoder(A, encoded_string, list_dic, bins, False)\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=5'>6</a>\u001b[0m \u001b[39m# print(np.allclose(image, reconstruct_image))\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000017?line=6'>7</a>\u001b[0m inletters \u001b[39m=\u001b[39m bitstring_to_bytes(encoded_string)\n",
"\u001b[1;32m/home/bryce/git/master/SaveableEncoderDecoder.ipynb Cell 6'\u001b[0m in \u001b[0;36mencoder\u001b[0;34m(error, list_dic, diff, bound, bins)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000005?line=18'>19</a>\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(encoded\u001b[39m.\u001b[39mshape[\u001b[39m0\u001b[39m]):\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000005?line=19'>20</a>\u001b[0m \u001b[39mfor\u001b[39;00m j \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(encoded\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m]):\n\u001b[0;32m---> <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000005?line=20'>21</a>\u001b[0m \u001b[39mif\u001b[39;00m i \u001b[39m==\u001b[39;49m \u001b[39m0\u001b[39;49m \u001b[39mor\u001b[39;00m i \u001b[39m==\u001b[39m encoded\u001b[39m.\u001b[39mshape[\u001b[39m0\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m \u001b[39mor\u001b[39;00m j \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m \u001b[39mor\u001b[39;00m j \u001b[39m==\u001b[39m encoded\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m]\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m:\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000005?line=21'>22</a>\u001b[0m returnable_encode \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m list_dic[\u001b[39m0\u001b[39m][encoded[i][j]]\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/SaveableEncoderDecoder.ipynb#ch0000005?line=22'>23</a>\u001b[0m \u001b[39melif\u001b[39;00m diff[i\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m][j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m] \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m bins[\u001b[39m0\u001b[39m]:\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"file_size_ratios = []\n",
"for i in range(200):\n",
" list_dic, image, new_error, diff, bound, predict, bins, A = huffman(images[i], 4, False)\n",
" encoded_string = encoder(new_error, list_dic, diff, bound, bins)\n",
" # reconstruct_image = decoder(A, encoded_string, list_dic, bins, False)\n",
" # print(np.allclose(image, reconstruct_image))\n",
" inletters = bitstring_to_bytes(encoded_string)\n",
" with open(\"MatrixNowString.txt\", 'w') as f:\n",
" f.write(inletters.decode(\"ISO-8859-1\"))\n",
" file_size_ratios.append((os.path.getsize('MatrixNowString.txt'))/os.path.getsize('images/1626032610_393963/1626032610_393963_0.tiff'))"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.5976777130753791\n"
]
}
],
"source": [
"print(np.mean(file_size_ratios))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"247\n"
]
}
],
"source": [] "source": []
}, },
{ {
......
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