Commit 76fd64f3 authored by Bryce Hepner's avatar Bryce Hepner

Just testbench changes

parent e6bd581c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 119, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -198,18 +198,17 @@ ...@@ -198,18 +198,17 @@
" #There is a huge memory leak here, no idea how or why\n", " #There is a huge memory leak here, no idea how or why\n",
" nodes = sorted(nodes, key=lambda x: x[1], reverse=True)\n", " nodes = sorted(nodes, key=lambda x: x[1], reverse=True)\n",
" return nodes[0][0]\n", " return nodes[0][0]\n",
"def decode_string(huffman_string, the_values, the_keys):\n", "def decode_string(huffman_string, the_keys, the_values):\n",
" for i in range(len(huffman_string)):\n", " for i in range(len(huffman_string)):\n",
" try:\n", " try:\n",
" return (int(the_keys[the_values.index(huffman_string[:i+1])]),huffman_string[i+1:])\n", " return (int(the_keys[the_values.index(huffman_string[:i+1])]),huffman_string[i+1:])\n",
" except:\n", " except:\n",
" pass\n", " pass\n"
" "
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 120, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -261,6 +260,7 @@ ...@@ -261,6 +260,7 @@
" \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,13 +311,14 @@ ...@@ -311,13 +311,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",
" 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": 121, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -334,7 +335,7 @@ ...@@ -334,7 +335,7 @@
" Return:\n", " Return:\n",
" encoded (512, 640): encoded matrix\n", " encoded (512, 640): encoded matrix\n",
" \"\"\"\n", " \"\"\"\n",
" returnableencode = \"\"\n", " returnable_encode = \"\"\n",
" # copy the error matrix (including the boundary)\n", " # copy the error matrix (including the boundary)\n",
" encoded = np.copy(error).astype(int).astype(str).astype(object)\n", " encoded = np.copy(error).astype(int).astype(str).astype(object)\n",
" #diff = np.reshape(diff,(510,638))\n", " #diff = np.reshape(diff,(510,638))\n",
...@@ -342,22 +343,22 @@ ...@@ -342,22 +343,22 @@
" for i in range(encoded.shape[0]):\n", " for i in range(encoded.shape[0]):\n",
" for j in range(encoded.shape[1]):\n", " for j in range(encoded.shape[1]):\n",
" if i == 0 or i == encoded.shape[0]-1 or j == 0 or j == encoded.shape[1]-1:\n", " if i == 0 or i == encoded.shape[0]-1 or j == 0 or j == encoded.shape[1]-1:\n",
" returnableencode += list_dic[0][encoded[i][j]]\n", " returnable_encode += list_dic[0][encoded[i][j]]\n",
" elif diff[i-1][j-1] <= bins[0]:\n", " elif diff[i-1][j-1] <= bins[0]:\n",
" returnableencode += list_dic[1][encoded[i][j]]\n", " returnable_encode += list_dic[1][encoded[i][j]]\n",
" elif diff[i-1][j-1] <= bins[1] and diff[i-1][j-1] > bins[0]:\n", " elif diff[i-1][j-1] <= bins[1] and diff[i-1][j-1] > bins[0]:\n",
" returnableencode +=list_dic[2][encoded[i][j]]\n", " returnable_encode +=list_dic[2][encoded[i][j]]\n",
" elif diff[i-1][j-1] <= bins[2] and diff[i-1][j-1] > bins[1]:\n", " elif diff[i-1][j-1] <= bins[2] and diff[i-1][j-1] > bins[1]:\n",
" returnableencode +=list_dic[3][encoded[i][j]]\n", " returnable_encode +=list_dic[3][encoded[i][j]]\n",
" else:\n", " else:\n",
" returnableencode += list_dic[4][encoded[i][j]]\n", " returnable_encode += list_dic[4][encoded[i][j]]\n",
"\n", "\n",
" return returnableencode" " return returnable_encode"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 133, "execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -374,7 +375,7 @@ ...@@ -374,7 +375,7 @@
" decode_matrix (512, 640): decoded matrix\n", " decode_matrix (512, 640): decoded matrix\n",
" \"\"\"\n", " \"\"\"\n",
" # change the dictionary back to list\n", " # change the dictionary back to list\n",
" # !!!!!WARNING!!!! has to change this part, eveytime you change the number of bins\n", " # !!!!!WARNING!!!! has to change this part, everytime you change the number of bins\n",
" the_keys0 = list(list_dic[0].keys())\n", " the_keys0 = list(list_dic[0].keys())\n",
" the_values0 = list(list_dic[0].values())\n", " the_values0 = list(list_dic[0].values())\n",
" \n", " \n",
...@@ -440,14 +441,13 @@ ...@@ -440,14 +441,13 @@
" else:\n", " else:\n",
" colorvalue, encoded_string = decode_string(encoded_string,the_keys=the_keys4, the_values=the_values4)\n", " colorvalue, encoded_string = decode_string(encoded_string,the_keys=the_keys4, the_values=the_values4)\n",
" decode_matrix[i][j] = colorvalue + int(predict)\n", " decode_matrix[i][j] = colorvalue + int(predict)\n",
" \n", "\n",
" \n",
" return decode_matrix.astype(int)" " return decode_matrix.astype(int)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 134, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -510,14 +510,14 @@ ...@@ -510,14 +510,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 136, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"True\n", "1\n",
"5\n" "5\n"
] ]
} }
...@@ -534,7 +534,7 @@ ...@@ -534,7 +534,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 131, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -543,7 +543,7 @@ ...@@ -543,7 +543,7 @@
"0.4232928466796875" "0.4232928466796875"
] ]
}, },
"execution_count": 131, "execution_count": 26,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -554,7 +554,7 @@ ...@@ -554,7 +554,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 149, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -573,7 +573,7 @@ ...@@ -573,7 +573,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 140, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -590,14 +590,14 @@ ...@@ -590,14 +590,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 169, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"398145\n" "2080569\n"
] ]
} }
], ],
...@@ -607,7 +607,7 @@ ...@@ -607,7 +607,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 167, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -633,7 +633,7 @@ ...@@ -633,7 +633,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 168, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -670,6 +670,13 @@ ...@@ -670,6 +670,13 @@
"(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": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
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