Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing test-cases related to Numpy I/O #121

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions test_cases/mask_image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
" Takes a 2D input image and a 2D binary mask image, then applies the mask to the input image and returns the result.\n",
" \"\"\"\n",
" import numpy as np\n",
" image = np.asarray(image)\n",
" mask = np.asarray(mask)\n",
" return image * mask"
]
},
Expand All @@ -27,27 +25,27 @@
"def check(candidate):\n",
" import numpy as np\n",
" \n",
" image = [\n",
" image = np.asarray([\n",
" [2,2,2,2,2],\n",
" [2,2,3,2,2],\n",
" [2,3,3,3,2],\n",
" [2,2,3,2,2],\n",
" [2,2,2,2,2],\n",
" ]\n",
" mask = [\n",
" ])\n",
" mask = np.asarray([\n",
" [0,0,0,0,0],\n",
" [0,0,1,0,0],\n",
" [0,1,1,1,0],\n",
" [0,0,1,0,0],\n",
" [0,0,0,0,0],\n",
" ]\n",
" reference = [\n",
" ])\n",
" reference = np.asarray([\n",
" [0,0,0,0,0],\n",
" [0,0,3,0,0],\n",
" [0,3,3,3,0],\n",
" [0,0,3,0,0],\n",
" [0,0,0,0,0],\n",
" ]\n",
" ])\n",
" masked_image = candidate(image,mask)\n",
" assert np.array_equal(masked_image, reference)"
]
Expand Down Expand Up @@ -87,7 +85,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
18 changes: 8 additions & 10 deletions test_cases/mean_squared_error.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
" \"\"\"\n",
" Computes the mean-squared-error of two images compared pixel-by-pixel\n",
" \"\"\"\n",
" import numpy as np\n",
" image1 = np.asarray(image1)\n",
" image2 = np.asarray(image2)\n",
" return ((image1 - image2)**2).mean()\n",
" # adapted from : https://stackoverflow.com/questions/16774849/mean-squared-error-in-numpy"
]
Expand All @@ -26,32 +23,33 @@
"outputs": [],
"source": [
"def check(candidate):\n",
" image1 = [\n",
" import numpy as np\n",
" image1 = np.asarray([\n",
" [0,0,0,0,0],\n",
" [0,1,0,0,0],\n",
" [0,0,0,0,0],\n",
" [0,0,0,2,0],\n",
" [0,0,0,0,0],\n",
" ]\n",
" image2 = [\n",
" ])\n",
" image2 = np.asarray([\n",
" [0,0,0,0,0],\n",
" [0,1,0,0,0],\n",
" [0,0,0,0,0],\n",
" [0,0,0,2,0],\n",
" [0,0,0,0,0],\n",
" ]\n",
" ])\n",
"\n",
" mse = candidate(image1,image2)\n",
" print(mse)\n",
" assert mse == 0\n",
"\n",
" image3 = [\n",
" image3 = np.asarray([\n",
" [0,0,0,0,0],\n",
" [0,0,0,0,0],\n",
" [0,0,0,0,0],\n",
" [0,0,0,0,0],\n",
" [0,0,0,0,0],\n",
" ]\n",
" ])\n",
"\n",
" mse = candidate(image1,image3)\n",
" print(mse)\n",
Expand Down Expand Up @@ -103,7 +101,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions test_cases/rgb_to_grey_image_transform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
" b = b / rgb_sum\n",
" \n",
" import numpy as np\n",
" channel_r = np.asarray(rgb_image)[...,0]\n",
" channel_g = np.asarray(rgb_image)[...,1]\n",
" channel_b = np.asarray(rgb_image)[...,2]\n",
" channel_r = rgb_image[...,0]\n",
" channel_g = rgb_image[...,1]\n",
" channel_b = rgb_image[...,2]\n",
" grey_image = channel_r * r + \\\n",
" channel_g * g + \\\n",
" channel_b * b\n",
Expand All @@ -38,10 +38,10 @@
"source": [
"def check(candidate):\n",
" import numpy as np\n",
" assert np.allclose(candidate([[[0,1,2], [3,3,3]]], 0.5, 0.25, 0.25),\n",
" assert np.allclose(candidate(np.asarray([[[0,1,2], [3,3,3]]]), 0.5, 0.25, 0.25),\n",
" [[0.75, 3]], atol=0.0001)\n",
"\n",
" assert np.allclose(candidate([[[0,1,2], [3,3,3]]], 1, 2, 2),\n",
" assert np.allclose(candidate(np.asarray([[[0,1,2], [3,3,3]]]), 1, 2, 2),\n",
" [[1.2, 3]], atol=0.0001)\n",
" "
]
Expand Down Expand Up @@ -89,7 +89,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
13 changes: 6 additions & 7 deletions test_cases/sum_images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
" \"\"\"\n",
" Sums two images pixel-by-pixel and returns the result\n",
" \"\"\"\n",
" import numpy as np\n",
" return np.asarray(image1) + np.asarray(image2)"
" return image1 + image2"
]
},
{
Expand All @@ -31,9 +30,9 @@
" \n",
" assert np.allclose(candidate(image1, image2), sum_image)\n",
"\n",
" image1 = [[1,2,3], [4,5,6]]\n",
" image2 = [[5,6,7], [0,1,2]]\n",
" sum_image = [[6,8,10],[4,6,8]]\n",
" image1 = np.asarray([[1,2,3], [4,5,6]])\n",
" image2 = np.asarray([[5,6,7], [0,1,2]])\n",
" sum_image = np.asarray([[6,8,10],[4,6,8]])\n",
" \n",
" assert np.allclose(candidate(image1, image2), sum_image)\n"
]
Expand All @@ -59,9 +58,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:heb]",
"language": "python",
"name": "python3"
"name": "conda-env-heb-py"
},
"language_info": {
"codemirror_mode": {
Expand Down