Commit 5c7cf95e authored by Kelly Chang's avatar Kelly Chang

kelly changes

parent e4df997c
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "d866df6f", "id": "5437bd8d",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## use MSE" "## use MSE"
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 50,
"id": "73412bc9", "id": "73412bc9",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -233,47 +233,38 @@ ...@@ -233,47 +233,38 @@
" fix this later. 1/25/22\n", " fix this later. 1/25/22\n",
" \"\"\"\n", " \"\"\"\n",
" \n", " \n",
"\n",
" image = tiff_list\n", " image = tiff_list\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 = image.astype(int)\n",
" row, col = image.shape\n", " A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" predict = np.empty([row,col]) # create a empty matrix to update prediction\n", " z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" predict[0,:] = np.copy(image[0,:]) # keep the first row from the image\n", " z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" predict[:,0] = np.copy(image[:,0]) # keep the first columen from the image\n", " z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" predict[-1,:] = np.copy(image[-1,:]) # keep the first row from the image\n", " z3 = image[1:-1,0:-2] # get all the forth pixel for the entire image\n",
" predict[:,-1] = np.copy(image[:,-1]) # keep the first columen from the image\n", " # calculate the out put of the system of equation\n",
" diff = np.empty([row,col])\n",
" diff[0,:] = np.zeros(col) # keep the first row from the image\n",
" diff[:,0] = np.zeros(row)\n",
" diff[-1,:] = np.zeros(col) # keep the first row from the image\n",
" diff[:,-1] = np.zeros(row)\n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]])\n",
" z0 = image[0:-2,0:-2]\n",
" z1 = image[0:-2,1:-1]\n",
" z2 = image[0:-2,2::]\n",
" z3 = image[1:-1,0:-2]\n",
" y0 = np.ravel(-z0+z2-z3)\n", " y0 = np.ravel(-z0+z2-z3)\n",
" y1 = np.ravel(z0+z1+z2)\n", " y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n", " y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n", " y = np.vstack((y0,y1,y2))\n",
" # use numpy solver to solve the system of equations all at once\n",
" predict = np.linalg.solve(A,y)[-1]\n", " predict = np.linalg.solve(A,y)[-1]\n",
" \n", " # flatten the neighbor pixlels 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",
" z3 = np.ravel(z3)\n", " z3 = np.ravel(z3)\n",
" neighbor = np.vstack((z0,z1,z2,z3)).T\n", " neighbor = np.vstack((z0,z1,z2,z3)).T\n",
" # calculate the difference\n",
" diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n", " diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n",
" \n", " # flatten the image to a vector\n",
" image = np.ravel(image[1:-1,1:-1])\n", " image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict, diff" " return image, predict, diff"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 51,
"id": "1bc0bed5", "id": "1bc0bed5",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -287,8 +278,8 @@ ...@@ -287,8 +278,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 52,
"id": "a8c46fb2", "id": "0f908e6c",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -296,7 +287,7 @@ ...@@ -296,7 +287,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"mean of error = 18.740279058331875\n", "mean of error = 18.740279058331875\n",
"time to run = 0.06311893463134766\n" "time to run = 0.07091403007507324\n"
] ]
}, },
{ {
...@@ -330,7 +321,7 @@ ...@@ -330,7 +321,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "0c73bbe2", "id": "fb798c32",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
...@@ -338,7 +329,7 @@ ...@@ -338,7 +329,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "1f19bb5d", "id": "23f8c8a7",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 44,
"id": "b7a550e0", "id": "b7a550e0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 51,
"id": "9ed20f84", "id": "9ed20f84",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -91,33 +91,35 @@ ...@@ -91,33 +91,35 @@
" 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 = image.astype(int)\n",
" row, col = image.shape\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]])\n", " z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z0 = image[0:-2,0:-2]\n", " z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z1 = image[0:-2,1:-1]\n", " z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z2 = image[0:-2,2::]\n", " z3 = image[1:-1,0:-2] # get all the forth pixel for the entire image\n",
" z3 = image[1:-1,0:-2]\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",
" y1 = np.ravel(z0+z1+z2)\n", " y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n", " y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n", " y = np.vstack((y0,y1,y2))\n",
"\n", " # use numpy solver to solve the system of equations all at once\n",
" predict = np.linalg.solve(A,y[:10])[-1]\n", " predict = np.linalg.solve(A,y)[-1]\n",
" \n", " # flatten the neighbor pixlels 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",
" z3 = np.ravel(z3)\n", " z3 = np.ravel(z3)\n",
" neighbor = np.vstack((z0,z1,z2,z3)).T\n", " neighbor = np.vstack((z0,z1,z2,z3)).T\n",
" diff = np.max(neighbor,axis = 1) - np.max(neighbor, axis=1)\n", " # calculate the difference\n",
" \n", " diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n",
" # flatten the image to a vector\n",
" image = np.ravel(image[1:-1,1:-1])\n", " image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict, diff" " return image, predict, diff\n",
"\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 49,
"id": "8e3ef654", "id": "8e3ef654",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -150,7 +152,7 @@ ...@@ -150,7 +152,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 52,
"id": "fa65dcd6", "id": "fa65dcd6",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
...@@ -160,8 +162,8 @@ ...@@ -160,8 +162,8 @@
"text": [ "text": [
"Average Error First and Second Added: 20.017164930235474\n", "Average Error First and Second Added: 20.017164930235474\n",
"Standard Deviaiton of Mean Errors: 0.16101183692475135\n", "Standard Deviaiton of Mean Errors: 0.16101183692475135\n",
"Average Difference: -53.678648426455226\n", "Average Difference: 53.678648426455226\n",
"Average Time per Image for First: 0.05081495642662048\n" "Average Time per Image for First: 0.04535740613937378\n"
] ]
} }
], ],
......
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "d866df6f", "id": "5437bd8d",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## use MSE" "## use MSE"
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 50,
"id": "73412bc9", "id": "73412bc9",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -233,47 +233,38 @@ ...@@ -233,47 +233,38 @@
" fix this later. 1/25/22\n", " fix this later. 1/25/22\n",
" \"\"\"\n", " \"\"\"\n",
" \n", " \n",
"\n",
" image = tiff_list\n", " image = tiff_list\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 = image.astype(int)\n",
" row, col = image.shape\n", " A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation\n",
" predict = np.empty([row,col]) # create a empty matrix to update prediction\n", " z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" predict[0,:] = np.copy(image[0,:]) # keep the first row from the image\n", " z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" predict[:,0] = np.copy(image[:,0]) # keep the first columen from the image\n", " z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" predict[-1,:] = np.copy(image[-1,:]) # keep the first row from the image\n", " z3 = image[1:-1,0:-2] # get all the forth pixel for the entire image\n",
" predict[:,-1] = np.copy(image[:,-1]) # keep the first columen from the image\n", " # calculate the out put of the system of equation\n",
" diff = np.empty([row,col])\n",
" diff[0,:] = np.zeros(col) # keep the first row from the image\n",
" diff[:,0] = np.zeros(row)\n",
" diff[-1,:] = np.zeros(col) # keep the first row from the image\n",
" diff[:,-1] = np.zeros(row)\n",
" A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]])\n",
" z0 = image[0:-2,0:-2]\n",
" z1 = image[0:-2,1:-1]\n",
" z2 = image[0:-2,2::]\n",
" z3 = image[1:-1,0:-2]\n",
" y0 = np.ravel(-z0+z2-z3)\n", " y0 = np.ravel(-z0+z2-z3)\n",
" y1 = np.ravel(z0+z1+z2)\n", " y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n", " y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n", " y = np.vstack((y0,y1,y2))\n",
" # use numpy solver to solve the system of equations all at once\n",
" predict = np.linalg.solve(A,y)[-1]\n", " predict = np.linalg.solve(A,y)[-1]\n",
" \n", " # flatten the neighbor pixlels 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",
" z3 = np.ravel(z3)\n", " z3 = np.ravel(z3)\n",
" neighbor = np.vstack((z0,z1,z2,z3)).T\n", " neighbor = np.vstack((z0,z1,z2,z3)).T\n",
" # calculate the difference\n",
" diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n", " diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n",
" \n", " # flatten the image to a vector\n",
" image = np.ravel(image[1:-1,1:-1])\n", " image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict, diff" " return image, predict, diff"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 51,
"id": "1bc0bed5", "id": "1bc0bed5",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -287,8 +278,8 @@ ...@@ -287,8 +278,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 52,
"id": "a8c46fb2", "id": "0f908e6c",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -296,7 +287,7 @@ ...@@ -296,7 +287,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"mean of error = 18.740279058331875\n", "mean of error = 18.740279058331875\n",
"time to run = 0.06311893463134766\n" "time to run = 0.07091403007507324\n"
] ]
}, },
{ {
...@@ -330,7 +321,7 @@ ...@@ -330,7 +321,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "0c73bbe2", "id": "fb798c32",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
...@@ -338,7 +329,7 @@ ...@@ -338,7 +329,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "1f19bb5d", "id": "23f8c8a7",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 44,
"id": "b7a550e0", "id": "b7a550e0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 51,
"id": "9ed20f84", "id": "9ed20f84",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -91,33 +91,35 @@ ...@@ -91,33 +91,35 @@
" 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 = image.astype(int)\n",
" row, col = image.shape\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]])\n", " z0 = image[0:-2,0:-2] # get all the first pixel for the entire image\n",
" z0 = image[0:-2,0:-2]\n", " z1 = image[0:-2,1:-1] # get all the second pixel for the entire image\n",
" z1 = image[0:-2,1:-1]\n", " z2 = image[0:-2,2::] # get all the third pixel for the entire image\n",
" z2 = image[0:-2,2::]\n", " z3 = image[1:-1,0:-2] # get all the forth pixel for the entire image\n",
" z3 = image[1:-1,0:-2]\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",
" y1 = np.ravel(z0+z1+z2)\n", " y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n", " y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n", " y = np.vstack((y0,y1,y2))\n",
"\n", " # use numpy solver to solve the system of equations all at once\n",
" predict = np.linalg.solve(A,y[:10])[-1]\n", " predict = np.linalg.solve(A,y)[-1]\n",
" \n", " # flatten the neighbor pixlels 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",
" z3 = np.ravel(z3)\n", " z3 = np.ravel(z3)\n",
" neighbor = np.vstack((z0,z1,z2,z3)).T\n", " neighbor = np.vstack((z0,z1,z2,z3)).T\n",
" diff = np.max(neighbor,axis = 1) - np.max(neighbor, axis=1)\n", " # calculate the difference\n",
" \n", " diff = np.max(neighbor,axis = 1) - np.min(neighbor, axis=1)\n",
" # flatten the image to a vector\n",
" image = np.ravel(image[1:-1,1:-1])\n", " image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict, diff" " return image, predict, diff\n",
"\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 49,
"id": "8e3ef654", "id": "8e3ef654",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -150,7 +152,7 @@ ...@@ -150,7 +152,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 52,
"id": "fa65dcd6", "id": "fa65dcd6",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
...@@ -160,8 +162,8 @@ ...@@ -160,8 +162,8 @@
"text": [ "text": [
"Average Error First and Second Added: 20.017164930235474\n", "Average Error First and Second Added: 20.017164930235474\n",
"Standard Deviaiton of Mean Errors: 0.16101183692475135\n", "Standard Deviaiton of Mean Errors: 0.16101183692475135\n",
"Average Difference: -53.678648426455226\n", "Average Difference: 53.678648426455226\n",
"Average Time per Image for First: 0.05081495642662048\n" "Average Time per Image for First: 0.04535740613937378\n"
] ]
} }
], ],
......
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