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
53e2bb11
Commit
53e2bb11
authored
Mar 12, 2022
by
Nathaniel Callens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
b88a3252
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
234 additions
and
94 deletions
+234
-94
Error_to_Image-checkpoint.ipynb
.ipynb_checkpoints/Error_to_Image-checkpoint.ipynb
+117
-47
Error_to_Image.ipynb
Error_to_Image.ipynb
+117
-47
No files found.
.ipynb_checkpoints/Error_to_Image-checkpoint.ipynb
View file @
53e2bb11
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
33
,
"execution_count":
2
,
"id": "dbef8759",
"metadata": {
"id": "dbef8759"
...
...
@@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
3
,
"id": "9ed20f84",
"metadata": {
"id": "9ed20f84"
...
...
@@ -100,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
4
,
"id": "ba2881d9",
"metadata": {},
"outputs": [],
...
...
@@ -112,17 +112,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count":
14
4,
"id": "11e95c34",
"metadata": {},
"outputs": [],
"source": [
"predict, diff, im, err, A = plot_hist(
num_images, 0
)"
"predict, diff, im, err, A = plot_hist(
images, 2
)"
]
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
139
,
"id": "434e4d2f",
"metadata": {},
"outputs": [],
...
...
@@ -147,7 +147,9 @@
" for c in range(1, columns-1):\n",
" z0, z1, z2, z3 = new_e[r-1][c-1], new_e[r-1][c], new_e[r-1][c+1], new_e[r][c-1]\n",
" y = np.vstack((-z0+z2-z3, z0+z1+z2, -z0-z1-z2-z3))\n",
"\n",
" \n",
" if r == 1 and c == 1:\n",
" print(np.linalg.solve(A,y)[-1])\n",
" \n",
" #Real solution that works, DO NOT DELETE\n",
" #new_e[r][c] = int(np.ceil(new_e[r][c] + np.linalg.solve(A,y)[-1]))\n",
...
...
@@ -160,17 +162,52 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
140
,
"id": "3cc609dc",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[22471.5]\n"
]
}
],
"source": [
"new_error = reconstruct(err, A)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 136,
"id": "5d290a0c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[22546, 22514, 22513, ..., 22581, 22576, 22587],\n",
" [22488, 67, -21, ..., -1, -1, 22576],\n",
" [22514, -15, -3, ..., 10, -45, 22575],\n",
" ...,\n",
" [22317, 82, -2, ..., -64, 5, 22937],\n",
" [22335, -33, 18, ..., 47, -16, 22932],\n",
" [22333, 22339, 22362, ..., 22952, 22947, 22961]])"
]
},
"execution_count": 136,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"err"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "706f2816",
"metadata": {},
"outputs": [],
...
...
@@ -194,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
9
,
"id": "530d2cab",
"metadata": {},
"outputs": [
...
...
@@ -293,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count":
9
,
"execution_count":
10
,
"id": "bb11dcd0",
"metadata": {},
"outputs": [],
...
...
@@ -341,7 +378,7 @@
},
{
"cell_type": "code",
"execution_count":
263
,
"execution_count":
108
,
"id": "c01fda28",
"metadata": {},
"outputs": [],
...
...
@@ -376,10 +413,8 @@
" encoding_dict = huffman_code_tree(node)\n",
" #encoded = [\"1\"+encoding[str(-i)] if i < 0 else \"0\"+encoding[str(i)] for i in error]\n",
" #print(time.time()-start)\n",
" encoded = new_error.reshape((512,640)).copy().astype(str)\n",
" \n",
" #encoded = np.zeros_like(new_error.reshape((512,640))).astype(str)\n",
" print(encoded)\n",
" encoded = new_error.reshape((512,640)).copy().astype(str).astype(object)\n",
"\n",
" for i in range(encoded.shape[0]):\n",
" for j in range(encoded.shape[1]):\n",
" if i == 0 and j == 0:\n",
...
...
@@ -388,60 +423,48 @@
" #print(encoding_dict[encoded[i][j]])\n",
" encoded[i][j] = encoding_dict[encoded[i][j]]\n",
" #print(encoded[i][j])\n",
" \n",
" return encoding_dict, encoded, new_error.reshape((512,640))\n",
"
\n",
" return encoding_dict, encoded, new_error.reshape((512,640))
, image
\n",
" #print(encoding)"
]
},
{
"cell_type": "code",
"execution_count":
264
,
"execution_count":
109
,
"id": "ffa858e8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[['22541' '-10' '14' ... '32' '48' '33']\n",
" ['7' '67' '-21' ... '-1' '-1' '77']\n",
" ['7' '-15' '-3' ... '10' '-45' '58']\n",
" ...\n",
" ['49' '82' '-2' ... '-64' '5' '151']\n",
" ['27' '-33' '18' ... '47' '-16' '208']\n",
" ['17' '0' '-5' ... '138' '207' '226']]\n"
]
}
],
"outputs": [],
"source": [
"encode_dict, encoding, error = enc_experiment(images, plot=False)"
"encode_dict, encoding, error
, orig_image
= enc_experiment(images, plot=False)"
]
},
{
"cell_type": "code",
"execution_count":
265
,
"id": "8
5815094
",
"execution_count":
110
,
"id": "8
dfdedc6
",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11110111110\n",
"92\n",
"11110111110001\n"
"[[22541 22531 22555 ... 22573 22589 22574]\n",
" [22548 22544 22530 ... 22607 22612 22618]\n",
" [22548 22544 22560 ... 22603 22605 22599]\n",
" ...\n",
" [22590 22593 22596 ... 22586 22627 22692]\n",
" [22568 22575 22555 ... 22625 22702 22749]\n",
" [22558 22541 22536 ... 22679 22748 22767]]\n"
]
}
],
"source": [
"print(encoding[0][100])\n",
"print(error[0][100])\n",
"print(encode_dict['92'])"
"print(orig_image)"
]
},
{
"cell_type": "code",
"execution_count":
null
,
"execution_count":
148
,
"id": "825cc48c",
"metadata": {},
"outputs": [],
...
...
@@ -451,14 +474,61 @@
" Function that accecpts the prediction matrix A for the linear system,\n",
" the encoded matrix of error values, and the encoding dicitonary.\n",
" \"\"\"\n",
" the_keys = list(encode_dict.keys())\n",
" the_values = list(encode_dict.values())\n",
" error_matrix = encoded_matrix.copy()\n",
" \n",
" for i in range(error_matrix.shape[0]):\n",
" for j in range(error_matrix.shape[1]):\n",
" if i == 0 and j == 0:\n",
" error_matrix[i][j] = encoded_matrix[i][j]\n",
" error_matrix[i][j] = int(encoded_matrix[i][j])\n",
" elif i == 0 or i == error_matrix.shape[0]-1 or j == 0 or j == error_matrix.shape[1]-1:\n",
" error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])]) + error_matrix[0][0]\n",
" else:\n",
" error_matrix[i][j] = encoding_dict."
" if j == 1 and i == 1:\n",
" z0, z1, z2, z3 = error_matrix[i-1][j-1], error_matrix[i-1][j], \\\n",
" error_matrix[i-1][j+1], error_matrix[i][j-1]\n",
"\n",
" y = np.vstack((-z0+z2-z3, z0+z1+z2, -z0-z1-z2-z3))\n",
" #Real solution that works, DO NOT DELETE\n",
" #new_e[r][c] = int(np.ceil(new_e[r][c] + np.linalg.solve(A,y)[-1]))\n",
"\n",
" print(int(the_keys[the_values.index(error_matrix[i,j])]))\n",
" print(np.linalg.solve(A,y)[-1])\n",
" error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])]) + \\\n",
" np.linalg.solve(A,y)[-1][0]\n",
" #error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])])\n",
" break\n",
" \n",
" return error_matrix"
]
},
{
"cell_type": "code",
"execution_count": 149,
"id": "ba1d2c2c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"67\n",
"[22555.]\n"
]
}
],
"source": [
"em = decoder(A, encoding, encode_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2cdce6d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
Error_to_Image.ipynb
View file @
53e2bb11
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
33
,
"execution_count":
2
,
"id": "dbef8759",
"metadata": {
"id": "dbef8759"
...
...
@@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
3
,
"id": "9ed20f84",
"metadata": {
"id": "9ed20f84"
...
...
@@ -100,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
4
,
"id": "ba2881d9",
"metadata": {},
"outputs": [],
...
...
@@ -112,17 +112,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count":
14
4,
"id": "11e95c34",
"metadata": {},
"outputs": [],
"source": [
"predict, diff, im, err, A = plot_hist(
num_images, 0
)"
"predict, diff, im, err, A = plot_hist(
images, 2
)"
]
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
139
,
"id": "434e4d2f",
"metadata": {},
"outputs": [],
...
...
@@ -147,7 +147,9 @@
" for c in range(1, columns-1):\n",
" z0, z1, z2, z3 = new_e[r-1][c-1], new_e[r-1][c], new_e[r-1][c+1], new_e[r][c-1]\n",
" y = np.vstack((-z0+z2-z3, z0+z1+z2, -z0-z1-z2-z3))\n",
"\n",
" \n",
" if r == 1 and c == 1:\n",
" print(np.linalg.solve(A,y)[-1])\n",
" \n",
" #Real solution that works, DO NOT DELETE\n",
" #new_e[r][c] = int(np.ceil(new_e[r][c] + np.linalg.solve(A,y)[-1]))\n",
...
...
@@ -160,17 +162,52 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
140
,
"id": "3cc609dc",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[22471.5]\n"
]
}
],
"source": [
"new_error = reconstruct(err, A)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 136,
"id": "5d290a0c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[22546, 22514, 22513, ..., 22581, 22576, 22587],\n",
" [22488, 67, -21, ..., -1, -1, 22576],\n",
" [22514, -15, -3, ..., 10, -45, 22575],\n",
" ...,\n",
" [22317, 82, -2, ..., -64, 5, 22937],\n",
" [22335, -33, 18, ..., 47, -16, 22932],\n",
" [22333, 22339, 22362, ..., 22952, 22947, 22961]])"
]
},
"execution_count": 136,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"err"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "706f2816",
"metadata": {},
"outputs": [],
...
...
@@ -194,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
9
,
"id": "530d2cab",
"metadata": {},
"outputs": [
...
...
@@ -293,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count":
9
,
"execution_count":
10
,
"id": "bb11dcd0",
"metadata": {},
"outputs": [],
...
...
@@ -341,7 +378,7 @@
},
{
"cell_type": "code",
"execution_count":
263
,
"execution_count":
108
,
"id": "c01fda28",
"metadata": {},
"outputs": [],
...
...
@@ -376,10 +413,8 @@
" encoding_dict = huffman_code_tree(node)\n",
" #encoded = [\"1\"+encoding[str(-i)] if i < 0 else \"0\"+encoding[str(i)] for i in error]\n",
" #print(time.time()-start)\n",
" encoded = new_error.reshape((512,640)).copy().astype(str)\n",
" \n",
" #encoded = np.zeros_like(new_error.reshape((512,640))).astype(str)\n",
" print(encoded)\n",
" encoded = new_error.reshape((512,640)).copy().astype(str).astype(object)\n",
"\n",
" for i in range(encoded.shape[0]):\n",
" for j in range(encoded.shape[1]):\n",
" if i == 0 and j == 0:\n",
...
...
@@ -388,60 +423,48 @@
" #print(encoding_dict[encoded[i][j]])\n",
" encoded[i][j] = encoding_dict[encoded[i][j]]\n",
" #print(encoded[i][j])\n",
" \n",
" return encoding_dict, encoded, new_error.reshape((512,640))\n",
"
\n",
" return encoding_dict, encoded, new_error.reshape((512,640))
, image
\n",
" #print(encoding)"
]
},
{
"cell_type": "code",
"execution_count":
264
,
"execution_count":
109
,
"id": "ffa858e8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[['22541' '-10' '14' ... '32' '48' '33']\n",
" ['7' '67' '-21' ... '-1' '-1' '77']\n",
" ['7' '-15' '-3' ... '10' '-45' '58']\n",
" ...\n",
" ['49' '82' '-2' ... '-64' '5' '151']\n",
" ['27' '-33' '18' ... '47' '-16' '208']\n",
" ['17' '0' '-5' ... '138' '207' '226']]\n"
]
}
],
"outputs": [],
"source": [
"encode_dict, encoding, error = enc_experiment(images, plot=False)"
"encode_dict, encoding, error
, orig_image
= enc_experiment(images, plot=False)"
]
},
{
"cell_type": "code",
"execution_count":
265
,
"id": "8
5815094
",
"execution_count":
110
,
"id": "8
dfdedc6
",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11110111110\n",
"92\n",
"11110111110001\n"
"[[22541 22531 22555 ... 22573 22589 22574]\n",
" [22548 22544 22530 ... 22607 22612 22618]\n",
" [22548 22544 22560 ... 22603 22605 22599]\n",
" ...\n",
" [22590 22593 22596 ... 22586 22627 22692]\n",
" [22568 22575 22555 ... 22625 22702 22749]\n",
" [22558 22541 22536 ... 22679 22748 22767]]\n"
]
}
],
"source": [
"print(encoding[0][100])\n",
"print(error[0][100])\n",
"print(encode_dict['92'])"
"print(orig_image)"
]
},
{
"cell_type": "code",
"execution_count":
null
,
"execution_count":
148
,
"id": "825cc48c",
"metadata": {},
"outputs": [],
...
...
@@ -451,14 +474,61 @@
" Function that accecpts the prediction matrix A for the linear system,\n",
" the encoded matrix of error values, and the encoding dicitonary.\n",
" \"\"\"\n",
" the_keys = list(encode_dict.keys())\n",
" the_values = list(encode_dict.values())\n",
" error_matrix = encoded_matrix.copy()\n",
" \n",
" for i in range(error_matrix.shape[0]):\n",
" for j in range(error_matrix.shape[1]):\n",
" if i == 0 and j == 0:\n",
" error_matrix[i][j] = encoded_matrix[i][j]\n",
" error_matrix[i][j] = int(encoded_matrix[i][j])\n",
" elif i == 0 or i == error_matrix.shape[0]-1 or j == 0 or j == error_matrix.shape[1]-1:\n",
" error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])]) + error_matrix[0][0]\n",
" else:\n",
" error_matrix[i][j] = encoding_dict."
" if j == 1 and i == 1:\n",
" z0, z1, z2, z3 = error_matrix[i-1][j-1], error_matrix[i-1][j], \\\n",
" error_matrix[i-1][j+1], error_matrix[i][j-1]\n",
"\n",
" y = np.vstack((-z0+z2-z3, z0+z1+z2, -z0-z1-z2-z3))\n",
" #Real solution that works, DO NOT DELETE\n",
" #new_e[r][c] = int(np.ceil(new_e[r][c] + np.linalg.solve(A,y)[-1]))\n",
"\n",
" print(int(the_keys[the_values.index(error_matrix[i,j])]))\n",
" print(np.linalg.solve(A,y)[-1])\n",
" error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])]) + \\\n",
" np.linalg.solve(A,y)[-1][0]\n",
" #error_matrix[i][j] = int(the_keys[the_values.index(error_matrix[i,j])])\n",
" break\n",
" \n",
" return error_matrix"
]
},
{
"cell_type": "code",
"execution_count": 149,
"id": "ba1d2c2c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"67\n",
"[22555.]\n"
]
}
],
"source": [
"em = decoder(A, encoding, encode_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2cdce6d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
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