Commit da4cfd74 authored by Nathaniel Callens's avatar Nathaniel Callens

updates

parent b3297cd5
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 130,
"id": "dbef8759",
"metadata": {
"id": "dbef8759"
......@@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 364,
"id": "9ed20f84",
"metadata": {
"id": "9ed20f84"
......@@ -43,14 +43,14 @@
" image = tiff_list[i]\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 = image.astype(int)\n",
" image_int = image.astype(np.int_)\n",
" \n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" \n",
" z0 = image[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",
" z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image[1:-1,0:-2] # get all the forth 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_int[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z2 = image_int[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image_int[1:-1,0:-2] # get all the fourth pixel for the entire image\n",
" \n",
" # calculate the out put of the system of equation\n",
" y0 = np.ravel(-z0+z2-z3)\n",
......@@ -62,7 +62,7 @@
" predict = np.linalg.solve(A,y)[-1]\n",
" #predict = []\n",
" \n",
" # flatten the neighbor pixlels and stack them together\n",
" # flatten the neighbor pixels and stack them together\n",
" z0 = np.ravel(z0)\n",
" z1 = np.ravel(z1)\n",
" z2 = np.ravel(z2)\n",
......@@ -74,40 +74,43 @@
" \n",
" \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",
" #Reshape the predictions to be a 2D array\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[:,-1] = image[:,-1]\n",
" predict[-1,:] = image[-1,:]\n",
" predict[-1,:] = image[-1,:]\"\"\"\n",
" \n",
" \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",
" #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",
" return predict, diff, image, error, A"
" return predict, diff, image_int, error, A"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 202,
"id": "ba2881d9",
"metadata": {},
"outputs": [],
"source": [
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_1\")"
"num_images = im_distribution(images, \"_9\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 365,
"id": "11e95c34",
"metadata": {},
"outputs": [],
......@@ -117,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 372,
"id": "434e4d2f",
"metadata": {},
"outputs": [],
......@@ -135,7 +138,75 @@
" Returns: \n",
" image (array): The reconstructed image\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"
]
}
],
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 130,
"id": "dbef8759",
"metadata": {
"id": "dbef8759"
......@@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 364,
"id": "9ed20f84",
"metadata": {
"id": "9ed20f84"
......@@ -43,14 +43,14 @@
" image = tiff_list[i]\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 = image.astype(int)\n",
" image_int = image.astype(np.int_)\n",
" \n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" \n",
" z0 = image[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",
" z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image[1:-1,0:-2] # get all the forth 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_int[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z2 = image_int[0:-2,2::] # get all the third pixel for the entire image\n",
" z3 = image_int[1:-1,0:-2] # get all the fourth pixel for the entire image\n",
" \n",
" # calculate the out put of the system of equation\n",
" y0 = np.ravel(-z0+z2-z3)\n",
......@@ -62,7 +62,7 @@
" predict = np.linalg.solve(A,y)[-1]\n",
" #predict = []\n",
" \n",
" # flatten the neighbor pixlels and stack them together\n",
" # flatten the neighbor pixels and stack them together\n",
" z0 = np.ravel(z0)\n",
" z1 = np.ravel(z1)\n",
" z2 = np.ravel(z2)\n",
......@@ -74,40 +74,43 @@
" \n",
" \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",
" #Reshape the predictions to be a 2D array\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[:,-1] = image[:,-1]\n",
" predict[-1,:] = image[-1,:]\n",
" predict[-1,:] = image[-1,:]\"\"\"\n",
" \n",
" \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",
" #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",
" return predict, diff, image, error, A"
" return predict, diff, image_int, error, A"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 202,
"id": "ba2881d9",
"metadata": {},
"outputs": [],
"source": [
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_1\")"
"num_images = im_distribution(images, \"_9\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 365,
"id": "11e95c34",
"metadata": {},
"outputs": [],
......@@ -117,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 372,
"id": "434e4d2f",
"metadata": {},
"outputs": [],
......@@ -135,7 +138,75 @@
" Returns: \n",
" image (array): The reconstructed image\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"
]
}
],
......
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