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
9fd6d565
Commit
9fd6d565
authored
Feb 05, 2022
by
Kelly Chang
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
5c7cf95e
2350ec98
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
775 additions
and
1 deletion
+775
-1
prediction_MSE_Scout-checkpoint.ipynb
.ipynb_checkpoints/prediction_MSE_Scout-checkpoint.ipynb
+383
-0
prediction_MSE_kelly-checkpoint.ipynb
.ipynb_checkpoints/prediction_MSE_kelly-checkpoint.ipynb
+8
-0
prediction_MSE_Scout.ipynb
prediction_MSE_Scout.ipynb
+383
-0
prediction_MSE_kelly.ipynb
prediction_MSE_kelly.ipynb
+1
-1
No files found.
.ipynb_checkpoints/prediction_MSE_Scout-checkpoint.ipynb
0 → 100644
View file @
9fd6d565
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "dbef8759",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from itertools import product\n",
"import os\n",
"import sys\n",
"from PIL import Image\n",
"from scipy.optimize import minimize\n",
"from time import time\n",
"from numpy import linalg as la"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b7a550e0",
"metadata": {},
"outputs": [],
"source": [
"def file_extractor(dirname=\"images\"):\n",
" files = os.listdir(dirname)\n",
" scenes = []\n",
" for file in files:\n",
" scenes.append(os.path.join(dirname, file))\n",
" return scenes\n",
"\n",
"def image_extractor(scenes):\n",
" image_folder = []\n",
" for scene in scenes:\n",
" files = os.listdir(scene)\n",
" for file in files:\n",
" image_folder.append(os.path.join(scene, file))\n",
" images = []\n",
" for folder in image_folder:\n",
" ims = os.listdir(folder)\n",
" for im in ims:\n",
" if im[-4:] == \".jp4\" or im[-7:] == \"_6.tiff\":\n",
" continue\n",
" else:\n",
" images.append(os.path.join(folder, im))\n",
" return images #returns a list of file paths to .tiff files in the specified directory given in file_extractor\n",
"\n",
"def im_distribution(images, num):\n",
" \"\"\"\n",
" Function that extracts tiff files from specific cameras and returns a list of all\n",
" the tiff files corresponding to that camera. i.e. all pictures labeled \"_7.tiff\" or otherwise\n",
" specified camera numbers.\n",
" \n",
" Parameters:\n",
" images (list): list of all tiff files, regardless of classification. This is NOT a list of directories but\n",
" of specific tiff files that can be opened right away. This is the list that we iterate through and \n",
" divide.\n",
" \n",
" num (str): a string designation for the camera number that we want to extract i.e. \"14\" for double digits\n",
" of \"_1\" for single digits.\n",
" \n",
" Returns:\n",
" tiff (list): A list of tiff files that have the specified designation from num. They are the files extracted\n",
" from the 'images' list that correspond to the given num.\n",
" \"\"\"\n",
" tiff = []\n",
" for im in images:\n",
" if im[-7:-5] == num:\n",
" tiff.append(im)\n",
" return tiff"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9ed20f84",
"metadata": {},
"outputs": [],
"source": [
"def plot_hist(tiff_list, i):\n",
" \"\"\"\n",
" This function is the leftovers from the first attempt to plot histograms.\n",
" As it stands it needs some work in order to function again. We will\n",
" fix this later. 1/25/22\n",
" \"\"\"\n",
" \n",
"\n",
" 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",
" row, col = image.shape\n",
" \"\"\"predict = np.empty([row,col]) # create a empty matrix to update prediction\n",
" predict[0,:] = np.copy(image[0,:]) # keep the first row from the image\n",
" predict[:,0] = np.copy(image[:,0]) # keep the first columen from the image\n",
" predict[-1,:] = np.copy(image[-1,:]) # keep the first row from the image\n",
" predict[:,-1] = np.copy(image[:,-1]) # keep the first columen from the image\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",
" y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n",
" predict = la.solve(A,y)[-1]\n",
" #diff = [(np.max([z0[r,c],z1[r,c],z2[r,c],z3[r,c]])-np.min([z0[r,c],z1[r,c],z2[r,c],z3[r,c]])) for r in range(0,row-2) for c in range(0,col-2)]\n",
" '''\n",
" for r in range(1,row-1): # loop through the rth row\n",
" for c in range(1,col-1): # loop through the cth column\n",
" actual_surrounding = np.array([image[r-1,c-1], image[r-1,c], image[r-1,c+1], image[r,c-1]])\n",
" #z = np.array([int(image[r-1,c-1]), int(image[r-1,c]), int(image[r-1,c+1]), int(image[r,c-1])])\n",
" z = np.array([image[r-1,c-1], image[r-1,c], image[r-1,c+1], image[r,c-1]])\n",
" y = np.array([-z[0]+z[2]-z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
" predict[r,c] = np.linalg.solve(A,y)[-1]\n",
" diff[r,c] = (np.max(actual_surrounding)-np.min(actual_surrounding))\n",
" predict = np.ravel(predict[1:-1,1:-1])\n",
" diff = np.ravel(diff[1:-1,1:-1])'''\n",
" image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict#, diff"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8e3ef654",
"metadata": {},
"outputs": [],
"source": [
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_9\")\n",
"error_mean = []\n",
"error_mean1 = []\n",
"diff_mean = []\n",
"times = []\n",
"times1 = []\n",
"all_error = []\n",
"for i in range(len(num_images)):\n",
" \"\"\"start1 = time()\n",
" image_1, predict_1, difference_1, x_s_1 = plot_hist(num_images, i, \"second\")\n",
" stop1 = time()\n",
" times1.append(stop1-start1)\n",
" error1 = np.abs(image_1-predict_1)\n",
" error_mean1.append(np.mean(np.ravel(error1)))\"\"\"\n",
" start = time()\n",
" image, predict = plot_hist(num_images, i)\n",
" stop = time()\n",
" times.append(stop-start)\n",
" error = np.abs(image-predict)\n",
" all_error.append(np.ravel(error))\n",
" error_mean.append(np.mean(np.ravel(error)))\n",
" #diff_mean.append(np.mean(np.ravel(difference)))\n",
" \n",
"#image, predict, difference = plot_hist(images, 0)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fa65dcd6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average Error First and Second Added: 20.017164930235474\n",
"233.22663391021266\n",
"Standard Deviaiton of Mean Errors: 0.16101183692475135\n",
"Average Time per Image for First: 0.023412495851516724\n"
]
}
],
"source": [
"print(f\"Average Error First and Second Added: {np.mean(error_mean)}\")\n",
"print(np.std(image))\n",
"print(f\"Standard Deviaiton of Mean Errors: {np.sqrt(np.var(error_mean))}\")\n",
"#print(f\"Average Difference: {np.mean(diff_mean)}\")\n",
"print(f\"Average Time per Image for First: {np.mean(times)}\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f592fa32",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0 1 2]\n",
" [3 4 5]\n",
" [6 7 8]]\n",
"[4 5]\n",
"[4 5]\n"
]
}
],
"source": [
"b = np.arange(9).reshape((3,3))\n",
"print(b)\n",
"print(b[1,1::])\n",
"print(b[1,1:])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "dda442ae",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'difference' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_10808/722042198.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0max\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_subplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mimage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdifference\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'o'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0malpha\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrcParams\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'font.size'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;36m20\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'difference' is not defined"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAAJDCAYAAAA8QNGHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUe0lEQVR4nO3dX4jld3nH8c/TXQP+qxGzik2ymJZo3AtTdIxStI2V1iQ3QfAiUQwNwhJqxMuEXuiFN/WiIGJ0WUII3piLGjSWaCgUTSGmzQZikjVEtpEm2whJVCwoNGzy9GKmMh1nM2cn59ndE18vODC/3/nOmQe+zPLe3zlzTnV3AACY8QdnegAAgFcysQUAMEhsAQAMElsAAIPEFgDAILEFADBox9iqqtuq6pmqevQk91dVfbmqjlXVw1X17uWPCQCwmha5snV7kite4v4rk1y8cTuY5GsvfywAgFeGHWOru+9N8ouXWHJ1kq/3uvuTnFtVb13WgAAAq2wZr9k6P8lTm46Pb5wDAPi9t3cJj1HbnNv2M4Cq6mDWn2rMa1/72vdccsklS/jxAACzHnzwwee6e99uvncZsXU8yYWbji9I8vR2C7v7cJLDSbK2ttZHjhxZwo8HAJhVVf+52+9dxtOIdyW5buOvEt+f5Ffd/bMlPC4AwMrb8cpWVX0jyeVJzquq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Jzb27OGquq+qLj0Tc7K9nfZv07r3VtULVfWx0zkfL22R/auqy6vqoao6WlU/ON0zsr0F/u18Q1V9p6p+tLF3Xud8lqiq26rqmZO9NdWum6W7x25Zf0H9fyT54yTnJPlRkgNb1lyV5LtZf6+u9yf5t8mZ3Ja6d3+W5I0bX19p786e2yL7t2ndv2T9NZkfO9Nzuy2+f0nOTfLjJPs3jt98pud2W3jv/i7JFze+3pfkF0nOOdOzu3WS/HmSdyd59CT376pZpq9s+aif1bXj3nX3fd39y43D+7P+/mqcHRb53UuSzyT5ZpJnTudw7GiR/ft4kju7+8kk6W57eHZYZO86yeurqpK8LuuxdeL0jsl2uvverO/HyeyqWaZjy0f9rK5T3ZdPZb32OTvsuH9VdX6SjyY5FM42i/z+vT3JG6vq+1X1YFVdd9qm46UssndfSfLOrL/59yNJPtvdL56e8XiZdtUsC731w8uwtI/64bRbeF+q6kNZj60PjE7EqVhk/76U5KbufmH9P9icRRbZv71J3pPkw0leneSHVXV/d/9kejhe0iJ795EkDyX5yyR/kuSfq+pfu/u/h2fj5dtVs0zH1tI+6ofTbqF9qap3Jbk1yZXd/fPTNBs7W2T/1pLcsRFa5yW5qqpOdPe3TsuEvJRF/+18rrt/neTXVXVvkkuTiK0za5G9uz7J3/f6i4COVdVPk1yS5N9Pz4i8DLtqlumnEX3Uz+race+qan+SO5N80v+mzzo77l93X9Tdb+vutyX5xyR/K7TOGov82/ntJB+sqr1V9Zok70vy2Gmek9+1yN49mfUrkqmqt2T9A46fOK1Tslu7apbRK1vto35W1oJ797kkb0ry1Y2rIyfaB6yeFRbcP85Si+xfdz9WVd9L8nCSF5Pc2t3b/rk6p8+Cv3tfSHJ7VT2S9aelburu587Y0PxWVX0jyeVJzquq40k+n+RVyctrFu8gDwAwyDvIAwAMElsAAIPEFgDAILEFADBIbAEADBJbAACDxBYAwCCxBQAw6H8BU0gXwe5IAxEAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure(figsize = (10,10))\n",
"ax = fig.add_subplot()\n",
"x = np.abs(predict-image)\n",
"y = difference\n",
"plt.plot(x,y,'o',alpha = 0.2)\n",
"plt.rcParams.update({'font.size': 20})\n",
"plt.xlabel(\"differnece to the true value\" )\n",
"plt.ylabel(\"differnece of min and max of true value of the surroundings\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58da6063",
"metadata": {},
"outputs": [],
"source": [
"image = Image.open(images[0]) #Open the image and read it as an Image object\n",
"image = np.array(image)[1:,:]\n",
"#z = np.array([image[1-1,1-1], image[1-1,1], image[1-1,1+1], image[1,1-1]])\n",
"z = np.array([22554,22552,22519,22561])\n",
"print(z)\n",
"'''A = np.array([[-3,0,1],[0,-3,3],[-1,-3,4]])\n",
"y = np.array([z[0]-z[2]+z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"a,b,c = np.linalg.solve(A,y)'''\n",
"A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]])\n",
"y = np.array([-z[0]+z[2]-z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"print(y)\n",
"a,b,c = np.linalg.solve(A,y)\n",
"print(a,b,c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2562feeb",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"i0 = (a*(-1) + b*(1) + c)\n",
"i1 = (a*(0) + b*(1) + c)\n",
"i2 = (a*(1) + b*(1) + c)\n",
"i3 = (a*(-1) + b*(0) + c)\n",
"print(sum([(i0-z[0])**2,(i1-z[1])**2,(i2-z[2])**2,(i3-z[3])**2]))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "470cc137",
"metadata": {},
"outputs": [],
"source": [
"a = 0\n",
"b = 2\n",
"c = 2\n",
"i0 = (a*(-1) + b*(1) + c)\n",
"i1 = (a*(0) + b*(1) + c)\n",
"i2 = (a*(1) + b*(1) + c)\n",
"i3 = (a*(-1) + b*(0) + c)\n",
"print(sum([(i0-z[0])**2,(i1-z[1])**2,(i2-z[2])**2,(i3-z[3])**2]))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3292b395",
"metadata": {},
"outputs": [],
"source": [
"#z = np.hstack((image[0,:3], image[1,0]))\n",
"#x = np.array([-1,0,1,-1])\n",
"#y = np.array([-1,-1,-1,0])\n",
"A = np.array([[-3,0,1],[0,-3,3],[1,3,-4]])\n",
"#y = np.array([z[0]-z[2]+z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"y = np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
"print(np.linalg.solve(A,y))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9687830",
"metadata": {},
"outputs": [],
"source": [
"0.5**2 + 1.5**2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e98eed4b",
"metadata": {},
"outputs": [],
"source": [
"y1= [0,1,2,3]\n",
"y2=[4,5,6,7]\n",
"y3=[8,9,10,11]\n",
"np.vstack((y1,y2,y3)).T"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7e88aab",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
.ipynb_checkpoints/prediction_MSE_kelly-checkpoint.ipynb
View file @
9fd6d565
...
...
@@ -152,7 +152,15 @@
},
{
"cell_type": "code",
<<<<<<< HEAD:.ipynb_checkpoints/prediction_MSE_kelly-checkpoint.ipynb
"execution_count": 52,
=======
<<<<<<< HEAD
"execution_count": 31,
=======
"execution_count": 43,
>>>>>>> e4df997c1a14994e77600c8c4e3e1a2ec84ff59e
>>>>>>> 2350ec9881b7954dc94449b36af098af82acbb95:.ipynb_checkpoints/prediction_MSE-checkpoint.ipynb
"id": "fa65dcd6",
"metadata": {},
"outputs": [
...
...
prediction_MSE_Scout.ipynb
0 → 100644
View file @
9fd6d565
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "dbef8759",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from itertools import product\n",
"import os\n",
"import sys\n",
"from PIL import Image\n",
"from scipy.optimize import minimize\n",
"from time import time\n",
"from numpy import linalg as la"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b7a550e0",
"metadata": {},
"outputs": [],
"source": [
"def file_extractor(dirname=\"images\"):\n",
" files = os.listdir(dirname)\n",
" scenes = []\n",
" for file in files:\n",
" scenes.append(os.path.join(dirname, file))\n",
" return scenes\n",
"\n",
"def image_extractor(scenes):\n",
" image_folder = []\n",
" for scene in scenes:\n",
" files = os.listdir(scene)\n",
" for file in files:\n",
" image_folder.append(os.path.join(scene, file))\n",
" images = []\n",
" for folder in image_folder:\n",
" ims = os.listdir(folder)\n",
" for im in ims:\n",
" if im[-4:] == \".jp4\" or im[-7:] == \"_6.tiff\":\n",
" continue\n",
" else:\n",
" images.append(os.path.join(folder, im))\n",
" return images #returns a list of file paths to .tiff files in the specified directory given in file_extractor\n",
"\n",
"def im_distribution(images, num):\n",
" \"\"\"\n",
" Function that extracts tiff files from specific cameras and returns a list of all\n",
" the tiff files corresponding to that camera. i.e. all pictures labeled \"_7.tiff\" or otherwise\n",
" specified camera numbers.\n",
" \n",
" Parameters:\n",
" images (list): list of all tiff files, regardless of classification. This is NOT a list of directories but\n",
" of specific tiff files that can be opened right away. This is the list that we iterate through and \n",
" divide.\n",
" \n",
" num (str): a string designation for the camera number that we want to extract i.e. \"14\" for double digits\n",
" of \"_1\" for single digits.\n",
" \n",
" Returns:\n",
" tiff (list): A list of tiff files that have the specified designation from num. They are the files extracted\n",
" from the 'images' list that correspond to the given num.\n",
" \"\"\"\n",
" tiff = []\n",
" for im in images:\n",
" if im[-7:-5] == num:\n",
" tiff.append(im)\n",
" return tiff"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9ed20f84",
"metadata": {},
"outputs": [],
"source": [
"def plot_hist(tiff_list, i):\n",
" \"\"\"\n",
" This function is the leftovers from the first attempt to plot histograms.\n",
" As it stands it needs some work in order to function again. We will\n",
" fix this later. 1/25/22\n",
" \"\"\"\n",
" \n",
"\n",
" 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",
" row, col = image.shape\n",
" \"\"\"predict = np.empty([row,col]) # create a empty matrix to update prediction\n",
" predict[0,:] = np.copy(image[0,:]) # keep the first row from the image\n",
" predict[:,0] = np.copy(image[:,0]) # keep the first columen from the image\n",
" predict[-1,:] = np.copy(image[-1,:]) # keep the first row from the image\n",
" predict[:,-1] = np.copy(image[:,-1]) # keep the first columen from the image\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",
" y1 = np.ravel(z0+z1+z2)\n",
" y2 = np.ravel(-z0-z1-z2-z3)\n",
" y = np.vstack((y0,y1,y2))\n",
" predict = la.solve(A,y)[-1]\n",
" #diff = [(np.max([z0[r,c],z1[r,c],z2[r,c],z3[r,c]])-np.min([z0[r,c],z1[r,c],z2[r,c],z3[r,c]])) for r in range(0,row-2) for c in range(0,col-2)]\n",
" '''\n",
" for r in range(1,row-1): # loop through the rth row\n",
" for c in range(1,col-1): # loop through the cth column\n",
" actual_surrounding = np.array([image[r-1,c-1], image[r-1,c], image[r-1,c+1], image[r,c-1]])\n",
" #z = np.array([int(image[r-1,c-1]), int(image[r-1,c]), int(image[r-1,c+1]), int(image[r,c-1])])\n",
" z = np.array([image[r-1,c-1], image[r-1,c], image[r-1,c+1], image[r,c-1]])\n",
" y = np.array([-z[0]+z[2]-z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
" predict[r,c] = np.linalg.solve(A,y)[-1]\n",
" diff[r,c] = (np.max(actual_surrounding)-np.min(actual_surrounding))\n",
" predict = np.ravel(predict[1:-1,1:-1])\n",
" diff = np.ravel(diff[1:-1,1:-1])'''\n",
" image = np.ravel(image[1:-1,1:-1])\n",
" return image, predict#, diff"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8e3ef654",
"metadata": {},
"outputs": [],
"source": [
"scenes = file_extractor()\n",
"images = image_extractor(scenes)\n",
"num_images = im_distribution(images, \"_9\")\n",
"error_mean = []\n",
"error_mean1 = []\n",
"diff_mean = []\n",
"times = []\n",
"times1 = []\n",
"all_error = []\n",
"for i in range(len(num_images)):\n",
" \"\"\"start1 = time()\n",
" image_1, predict_1, difference_1, x_s_1 = plot_hist(num_images, i, \"second\")\n",
" stop1 = time()\n",
" times1.append(stop1-start1)\n",
" error1 = np.abs(image_1-predict_1)\n",
" error_mean1.append(np.mean(np.ravel(error1)))\"\"\"\n",
" start = time()\n",
" image, predict = plot_hist(num_images, i)\n",
" stop = time()\n",
" times.append(stop-start)\n",
" error = np.abs(image-predict)\n",
" all_error.append(np.ravel(error))\n",
" error_mean.append(np.mean(np.ravel(error)))\n",
" #diff_mean.append(np.mean(np.ravel(difference)))\n",
" \n",
"#image, predict, difference = plot_hist(images, 0)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fa65dcd6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average Error First and Second Added: 20.017164930235474\n",
"233.22663391021266\n",
"Standard Deviaiton of Mean Errors: 0.16101183692475135\n",
"Average Time per Image for First: 0.023412495851516724\n"
]
}
],
"source": [
"print(f\"Average Error First and Second Added: {np.mean(error_mean)}\")\n",
"print(np.std(image))\n",
"print(f\"Standard Deviaiton of Mean Errors: {np.sqrt(np.var(error_mean))}\")\n",
"#print(f\"Average Difference: {np.mean(diff_mean)}\")\n",
"print(f\"Average Time per Image for First: {np.mean(times)}\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f592fa32",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0 1 2]\n",
" [3 4 5]\n",
" [6 7 8]]\n",
"[4 5]\n",
"[4 5]\n"
]
}
],
"source": [
"b = np.arange(9).reshape((3,3))\n",
"print(b)\n",
"print(b[1,1::])\n",
"print(b[1,1:])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "dda442ae",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'difference' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_10808/722042198.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0max\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_subplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mimage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdifference\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'o'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0malpha\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrcParams\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'font.size'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;36m20\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'difference' is not defined"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAAJDCAYAAAA8QNGHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUe0lEQVR4nO3dX4jld3nH8c/TXQP+qxGzik2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Xd/fPTNBs7W2T/1pLcsRFa5yW5qqpOdPe3TsuEvJRF/+18rrt/neTXVXVvkkuTiK0za5G9uz7J3/f6i4COVdVPk1yS5N9Pz4i8DLtqlumnEX3Uz+race+qan+SO5N80v+mzzo77l93X9Tdb+vutyX5xyR/K7TOGov82/ntJB+sqr1V9Zok70vy2Gmek9+1yN49mfUrkqmqt2T9A46fOK1Tslu7apbRK1vto35W1oJ797kkb0ry1Y2rIyfaB6yeFRbcP85Si+xfdz9WVd9L8nCSF5Pc2t3b/rk6p8+Cv3tfSHJ7VT2S9aelburu587Y0PxWVX0jyeVJzquq40k+n+RVyctrFu8gDwAwyDvIAwAMElsAAIPEFgDAILEFADBIbAEADBJbAACDxBYAwCCxBQAw6H8BU0gXwe5IAxEAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure(figsize = (10,10))\n",
"ax = fig.add_subplot()\n",
"x = np.abs(predict-image)\n",
"y = difference\n",
"plt.plot(x,y,'o',alpha = 0.2)\n",
"plt.rcParams.update({'font.size': 20})\n",
"plt.xlabel(\"differnece to the true value\" )\n",
"plt.ylabel(\"differnece of min and max of true value of the surroundings\")\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58da6063",
"metadata": {},
"outputs": [],
"source": [
"image = Image.open(images[0]) #Open the image and read it as an Image object\n",
"image = np.array(image)[1:,:]\n",
"#z = np.array([image[1-1,1-1], image[1-1,1], image[1-1,1+1], image[1,1-1]])\n",
"z = np.array([22554,22552,22519,22561])\n",
"print(z)\n",
"'''A = np.array([[-3,0,1],[0,-3,3],[-1,-3,4]])\n",
"y = np.array([z[0]-z[2]+z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"a,b,c = np.linalg.solve(A,y)'''\n",
"A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]])\n",
"y = np.array([-z[0]+z[2]-z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"print(y)\n",
"a,b,c = np.linalg.solve(A,y)\n",
"print(a,b,c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2562feeb",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"i0 = (a*(-1) + b*(1) + c)\n",
"i1 = (a*(0) + b*(1) + c)\n",
"i2 = (a*(1) + b*(1) + c)\n",
"i3 = (a*(-1) + b*(0) + c)\n",
"print(sum([(i0-z[0])**2,(i1-z[1])**2,(i2-z[2])**2,(i3-z[3])**2]))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "470cc137",
"metadata": {},
"outputs": [],
"source": [
"a = 0\n",
"b = 2\n",
"c = 2\n",
"i0 = (a*(-1) + b*(1) + c)\n",
"i1 = (a*(0) + b*(1) + c)\n",
"i2 = (a*(1) + b*(1) + c)\n",
"i3 = (a*(-1) + b*(0) + c)\n",
"print(sum([(i0-z[0])**2,(i1-z[1])**2,(i2-z[2])**2,(i3-z[3])**2]))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3292b395",
"metadata": {},
"outputs": [],
"source": [
"#z = np.hstack((image[0,:3], image[1,0]))\n",
"#x = np.array([-1,0,1,-1])\n",
"#y = np.array([-1,-1,-1,0])\n",
"A = np.array([[-3,0,1],[0,-3,3],[1,3,-4]])\n",
"#y = np.array([z[0]-z[2]+z[3], z[0]+z[1]+z[2], -z[0]-z[1]-z[2]-z[3]])\n",
"y = np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
"print(np.linalg.solve(A,y))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9687830",
"metadata": {},
"outputs": [],
"source": [
"0.5**2 + 1.5**2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e98eed4b",
"metadata": {},
"outputs": [],
"source": [
"y1= [0,1,2,3]\n",
"y2=[4,5,6,7]\n",
"y3=[8,9,10,11]\n",
"np.vstack((y1,y2,y3)).T"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7e88aab",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
prediction_MSE_kelly.ipynb
View file @
9fd6d565
...
...
@@ -199,7 +199,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
9.
1"
"version": "3.
8.1
1"
}
},
"nbformat": 4,
...
...
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