Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
image-compression
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
image-compression
Commits
76fd64f3
Commit
76fd64f3
authored
Jun 01, 2022
by
Bryce Hepner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just testbench changes
parent
e6bd581c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
31 deletions
+38
-31
SaveableEncoderDecoder.ipynb
SaveableEncoderDecoder.ipynb
+38
-31
No files found.
SaveableEncoderDecoder.ipynb
View file @
76fd64f3
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
9
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
10
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -72,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
11
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 1
19
,
"execution_count": 1
2
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -198,18 +198,17 @@
" #There is a huge memory leak here, no idea how or why\n",
" nodes = sorted(nodes, key=lambda x: x[1], reverse=True)\n",
" return nodes[0][0]\n",
"def decode_string(huffman_string, the_
values, the_key
s):\n",
"def decode_string(huffman_string, the_
keys, the_value
s):\n",
" for i in range(len(huffman_string)):\n",
" try:\n",
" return (int(the_keys[the_values.index(huffman_string[:i+1])]),huffman_string[i+1:])\n",
" except:\n",
" pass\n",
" "
" pass\n"
]
},
{
"cell_type": "code",
"execution_count": 1
20
,
"execution_count": 1
8
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -261,6 +260,7 @@
" \n",
" # create a list of huffman table\n",
" huffman_encoding_list = [huffman_encoding_dict]\n",
" print(len(huffman_encoding_list))\n",
" n = len(bins)\n",
" \n",
" # loop through different bins\n",
...
...
@@ -311,13 +311,14 @@
" # huffman_encoding_list = list(set(huffman_encoding_list))\n",
" diff = np.reshape(diff,(510,638))\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",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 1
21
,
"execution_count": 1
9
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -334,7 +335,7 @@
" Return:\n",
" encoded (512, 640): encoded matrix\n",
" \"\"\"\n",
" returnableencode = \"\"\n",
" returnable
_
encode = \"\"\n",
" # copy the error matrix (including the boundary)\n",
" encoded = np.copy(error).astype(int).astype(str).astype(object)\n",
" #diff = np.reshape(diff,(510,638))\n",
...
...
@@ -342,22 +343,22 @@
" for i in range(encoded.shape[0]):\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",
" 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",
" 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",
" 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",
" returnableencode +=list_dic[3][encoded[i][j]]\n",
" returnable
_
encode +=list_dic[3][encoded[i][j]]\n",
" else:\n",
" returnableencode += list_dic[4][encoded[i][j]]\n",
" returnable
_
encode += list_dic[4][encoded[i][j]]\n",
"\n",
" return returnableencode"
" return returnable
_
encode"
]
},
{
"cell_type": "code",
"execution_count":
133
,
"execution_count":
20
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -374,7 +375,7 @@
" decode_matrix (512, 640): decoded matrix\n",
" \"\"\"\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, eve
r
ytime you change the number of bins\n",
" the_keys0 = list(list_dic[0].keys())\n",
" the_values0 = list(list_dic[0].values())\n",
" \n",
...
...
@@ -440,14 +441,13 @@
" else:\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",
" \n",
" \n",
"\n",
" return decode_matrix.astype(int)"
]
},
{
"cell_type": "code",
"execution_count":
134
,
"execution_count":
21
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -510,14 +510,14 @@
},
{
"cell_type": "code",
"execution_count":
136
,
"execution_count":
22
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"
True
\n",
"
1
\n",
"5\n"
]
}
...
...
@@ -534,7 +534,7 @@
},
{
"cell_type": "code",
"execution_count":
131
,
"execution_count":
26
,
"metadata": {},
"outputs": [
{
...
...
@@ -543,7 +543,7 @@
"0.4232928466796875"
]
},
"execution_count":
131
,
"execution_count":
26
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -554,7 +554,7 @@
},
{
"cell_type": "code",
"execution_count": 1
49
,
"execution_count": 1
1
,
"metadata": {},
"outputs": [
{
...
...
@@ -573,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": 1
40
,
"execution_count": 1
2
,
"metadata": {},
"outputs": [
{
...
...
@@ -590,14 +590,14 @@
},
{
"cell_type": "code",
"execution_count": 1
69
,
"execution_count": 1
3
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"
398145
\n"
"
2080569
\n"
]
}
],
...
...
@@ -607,7 +607,7 @@
},
{
"cell_type": "code",
"execution_count": 1
67
,
"execution_count": 1
4
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -633,7 +633,7 @@
},
{
"cell_type": "code",
"execution_count": 1
68
,
"execution_count": 1
5
,
"metadata": {},
"outputs": [
{
...
...
@@ -670,6 +670,13 @@
"(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",
"execution_count": null,
...
...
Write
Preview
Markdown
is supported
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