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
Nathaniel Callens
Image Compression
Commits
da4cfd74
Commit
da4cfd74
authored
Mar 01, 2022
by
Nathaniel Callens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
b3297cd5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
178 additions
and
36 deletions
+178
-36
Error_to_Image-checkpoint.ipynb
.ipynb_checkpoints/Error_to_Image-checkpoint.ipynb
+89
-18
Error_to_Image.ipynb
Error_to_Image.ipynb
+89
-18
No files found.
.ipynb_checkpoints/Error_to_Image-checkpoint.ipynb
View file @
da4cfd74
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
"cells": [
"cells": [
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
130
,
"id": "dbef8759",
"id": "dbef8759",
"metadata": {
"metadata": {
"id": "dbef8759"
"id": "dbef8759"
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
20
,
"execution_count":
364
,
"id": "9ed20f84",
"id": "9ed20f84",
"metadata": {
"metadata": {
"id": "9ed20f84"
"id": "9ed20f84"
...
@@ -43,14 +43,14 @@
...
@@ -43,14 +43,14 @@
" image = tiff_list[i]\n",
" image = tiff_list[i]\n",
" image = Image.open(image) #Open the image and read it as an Image object\n",
" image = Image.open(image) #Open the image and read it as an Image object\n",
" image = np.array(image)[1:,:] #Convert to an array, leaving out the first row because the first row is just housekeeping data\n",
" image = np.array(image)[1:,:] #Convert to an array, leaving out the first row because the first row is just housekeeping data\n",
" image
= image.astype(int
)\n",
" image
_int = image.astype(np.int_
)\n",
" \n",
" \n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" \n",
" \n",
" z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z0 = image
_int
[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z1 = image
_int
[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z2 = image
_int
[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image
[1:-1,0:-2] # get all the fo
rth pixel for the entire image\n",
" z3 = image
_int[1:-1,0:-2] # get all the fou
rth pixel for the entire image\n",
" \n",
" \n",
" # calculate the out put of the system of equation\n",
" # calculate the out put of the system of equation\n",
" y0 = np.ravel(-z0+z2-z3)\n",
" y0 = np.ravel(-z0+z2-z3)\n",
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
" predict = np.linalg.solve(A,y)[-1]\n",
" predict = np.linalg.solve(A,y)[-1]\n",
" #predict = []\n",
" #predict = []\n",
" \n",
" \n",
" # flatten the neighbor pix
l
els and stack them together\n",
" # flatten the neighbor pixels and stack them together\n",
" z0 = np.ravel(z0)\n",
" z0 = np.ravel(z0)\n",
" z1 = np.ravel(z1)\n",
" z1 = np.ravel(z1)\n",
" z2 = np.ravel(z2)\n",
" z2 = np.ravel(z2)\n",
...
@@ -74,40 +74,43 @@
...
@@ -74,40 +74,43 @@
" \n",
" \n",
" \n",
" \n",
" # flatten the image to a vector\n",
" # flatten the image to a vector\n",
" small_image = image[1:-1,1:-1]\n",
" small_image = image
_int
[1:-1,1:-1]\n",
" \n",
" \n",
" #Reshape the predictions to be a 2D array\n",
" #Reshape the predictions to be a 2D array\n",
" predict = np.pad(predict.reshape(510,638), pad_width=1)\n",
" predict = np.pad(predict.reshape(510,638), pad_width=1)\n",
" predict[0,:] = image[0,:]\n",
"
\"\"\"
predict[0,:] = image[0,:]\n",
" predict[:,0] = image[:,0]\n",
" predict[:,0] = image[:,0]\n",
" predict[:,-1] = image[:,-1]\n",
" predict[:,-1] = image[:,-1]\n",
" predict[-1,:] = image[-1,:]\n",
" predict[-1,:] = image[-1,:]\
"\"\"\
n",
" \n",
" \n",
" \n",
" \n",
" #Calculate the error between the original image and our predictions\n",
" #Calculate the error between the original image and our predictions\n",
" #Note that we only predicted on the inside square of the original image, excluding\n",
" #Note that we only predicted on the inside square of the original image, excluding\n",
" #The first row, column and last row, column\n",
" #The first row, column and last row, column\n",
" error = image - predict\n",
" #error = (image_int - predict).astype(int) #Experiment\n",
" \n",
" #this one works\n",
" error = image_int - predict\n",
"\n",
"\n",
" \n",
" \n",
" return predict, diff, image, error, A"
" return predict, diff, image
_int
, error, A"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
18
,
"execution_count":
202
,
"id": "ba2881d9",
"id": "ba2881d9",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"scenes = file_extractor()\n",
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_
1
\")"
"num_images = im_distribution(images, \"_
9
\")"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
24
,
"execution_count":
365
,
"id": "11e95c34",
"id": "11e95c34",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -117,7 +120,7 @@
...
@@ -117,7 +120,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
372
,
"id": "434e4d2f",
"id": "434e4d2f",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -135,8 +138,76 @@
...
@@ -135,8 +138,76 @@
" Returns: \n",
" Returns: \n",
" image (array): The reconstructed image\n",
" image (array): The reconstructed image\n",
" \"\"\"\n",
" \"\"\"\n",
" new_e = error.copy()\n",
" rows, columns = new_e.shape\n",
"\n",
" for r in range(1, rows-1):\n",
" 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",
" if r == 345 and c == 421:\n",
" print(new_e[r][c])\n",
" print(np.linalg.solve(A,y)[-1])\n",
" print(new_e[r][c] + np.linalg.solve(A,y)[-1])\n",
" print(np.ceil(new_e[r][c] + 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",
" \n",
" #new_e[r][c] = new_e[r][c] + np.ceil(np.linalg.solve(A,y)[-1])\n",
" \n",
" return new_e.astype(int)\n",
" "
" "
]
]
},
{
"cell_type": "code",
"execution_count": 373,
"id": "ef632a8f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.499999999992724\n",
"[22627.5]\n",
"[22631.]\n",
"[22631.]\n"
]
}
],
"source": [
"new_error = reconstruct(err, A)"
]
},
{
"cell_type": "code",
"execution_count": 374,
"id": "6e6fb5cd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" ...,\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True]])"
]
},
"execution_count": 374,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_error == im"
]
}
}
],
],
"metadata": {
"metadata": {
...
...
Error_to_Image.ipynb
View file @
da4cfd74
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
"cells": [
"cells": [
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
130
,
"id": "dbef8759",
"id": "dbef8759",
"metadata": {
"metadata": {
"id": "dbef8759"
"id": "dbef8759"
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
20
,
"execution_count":
364
,
"id": "9ed20f84",
"id": "9ed20f84",
"metadata": {
"metadata": {
"id": "9ed20f84"
"id": "9ed20f84"
...
@@ -43,14 +43,14 @@
...
@@ -43,14 +43,14 @@
" image = tiff_list[i]\n",
" image = tiff_list[i]\n",
" image = Image.open(image) #Open the image and read it as an Image object\n",
" image = Image.open(image) #Open the image and read it as an Image object\n",
" image = np.array(image)[1:,:] #Convert to an array, leaving out the first row because the first row is just housekeeping data\n",
" image = np.array(image)[1:,:] #Convert to an array, leaving out the first row because the first row is just housekeeping data\n",
" image
= image.astype(int
)\n",
" image
_int = image.astype(np.int_
)\n",
" \n",
" \n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" \n",
" \n",
" z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z0 = image
_int
[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z1 = image
_int
[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z2 = image
_int
[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image
[1:-1,0:-2] # get all the fo
rth pixel for the entire image\n",
" z3 = image
_int[1:-1,0:-2] # get all the fou
rth pixel for the entire image\n",
" \n",
" \n",
" # calculate the out put of the system of equation\n",
" # calculate the out put of the system of equation\n",
" y0 = np.ravel(-z0+z2-z3)\n",
" y0 = np.ravel(-z0+z2-z3)\n",
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
" predict = np.linalg.solve(A,y)[-1]\n",
" predict = np.linalg.solve(A,y)[-1]\n",
" #predict = []\n",
" #predict = []\n",
" \n",
" \n",
" # flatten the neighbor pix
l
els and stack them together\n",
" # flatten the neighbor pixels and stack them together\n",
" z0 = np.ravel(z0)\n",
" z0 = np.ravel(z0)\n",
" z1 = np.ravel(z1)\n",
" z1 = np.ravel(z1)\n",
" z2 = np.ravel(z2)\n",
" z2 = np.ravel(z2)\n",
...
@@ -74,40 +74,43 @@
...
@@ -74,40 +74,43 @@
" \n",
" \n",
" \n",
" \n",
" # flatten the image to a vector\n",
" # flatten the image to a vector\n",
" small_image = image[1:-1,1:-1]\n",
" small_image = image
_int
[1:-1,1:-1]\n",
" \n",
" \n",
" #Reshape the predictions to be a 2D array\n",
" #Reshape the predictions to be a 2D array\n",
" predict = np.pad(predict.reshape(510,638), pad_width=1)\n",
" predict = np.pad(predict.reshape(510,638), pad_width=1)\n",
" predict[0,:] = image[0,:]\n",
"
\"\"\"
predict[0,:] = image[0,:]\n",
" predict[:,0] = image[:,0]\n",
" predict[:,0] = image[:,0]\n",
" predict[:,-1] = image[:,-1]\n",
" predict[:,-1] = image[:,-1]\n",
" predict[-1,:] = image[-1,:]\n",
" predict[-1,:] = image[-1,:]\
"\"\"\
n",
" \n",
" \n",
" \n",
" \n",
" #Calculate the error between the original image and our predictions\n",
" #Calculate the error between the original image and our predictions\n",
" #Note that we only predicted on the inside square of the original image, excluding\n",
" #Note that we only predicted on the inside square of the original image, excluding\n",
" #The first row, column and last row, column\n",
" #The first row, column and last row, column\n",
" error = image - predict\n",
" #error = (image_int - predict).astype(int) #Experiment\n",
" \n",
" #this one works\n",
" error = image_int - predict\n",
"\n",
"\n",
" \n",
" \n",
" return predict, diff, image, error, A"
" return predict, diff, image
_int
, error, A"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
18
,
"execution_count":
202
,
"id": "ba2881d9",
"id": "ba2881d9",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"scenes = file_extractor()\n",
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_
1
\")"
"num_images = im_distribution(images, \"_
9
\")"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
24
,
"execution_count":
365
,
"id": "11e95c34",
"id": "11e95c34",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -117,7 +120,7 @@
...
@@ -117,7 +120,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
372
,
"id": "434e4d2f",
"id": "434e4d2f",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
...
@@ -135,8 +138,76 @@
...
@@ -135,8 +138,76 @@
" Returns: \n",
" Returns: \n",
" image (array): The reconstructed image\n",
" image (array): The reconstructed image\n",
" \"\"\"\n",
" \"\"\"\n",
" new_e = error.copy()\n",
" rows, columns = new_e.shape\n",
"\n",
" for r in range(1, rows-1):\n",
" 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",
" if r == 345 and c == 421:\n",
" print(new_e[r][c])\n",
" print(np.linalg.solve(A,y)[-1])\n",
" print(new_e[r][c] + np.linalg.solve(A,y)[-1])\n",
" print(np.ceil(new_e[r][c] + 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",
" \n",
" #new_e[r][c] = new_e[r][c] + np.ceil(np.linalg.solve(A,y)[-1])\n",
" \n",
" return new_e.astype(int)\n",
" "
" "
]
]
},
{
"cell_type": "code",
"execution_count": 373,
"id": "ef632a8f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.499999999992724\n",
"[22627.5]\n",
"[22631.]\n",
"[22631.]\n"
]
}
],
"source": [
"new_error = reconstruct(err, A)"
]
},
{
"cell_type": "code",
"execution_count": 374,
"id": "6e6fb5cd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" ...,\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True],\n",
" [ True, True, True, ..., True, True, True]])"
]
},
"execution_count": 374,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_error == im"
]
}
}
],
],
"metadata": {
"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